Skip to content

Commit bc3afb2

Browse files
committed
log_ignore_path env var now takes a regex
1 parent ced7692 commit bc3afb2

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ app.all('*', (req, res) => {
175175
}
176176

177177
//Certain paths can be ignored in the container logs, useful to reduce noise from healthchecks
178-
if (process.env.LOG_IGNORE_PATH != req.path) {
178+
if (!process.env.LOG_IGNORE_PATH || !new RegExp(process.env.LOG_IGNORE_PATH).test(req.path)) {
179179

180180
let spacer = 4;
181181
if(process.env.LOG_WITHOUT_NEWLINE){

tests.sh

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ docker stop http-echo-tests
270270
sleep 5
271271

272272

273-
message " Start container with LOG_IGNORE_PATH "
273+
message " Start container with LOG_IGNORE_PATH (normal path)"
274274
docker run -d --rm -e LOG_IGNORE_PATH=/ping --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:testing
275275
sleep 5
276276
curl -s -k -X POST -d "banana" https://localhost:8443/ping > /dev/null
@@ -285,6 +285,38 @@ else
285285
exit 1
286286
fi
287287

288+
message " Stop containers "
289+
docker stop http-echo-tests
290+
sleep 5
291+
292+
message " Start container with LOG_IGNORE_PATH (regex path)"
293+
docker run -d --rm -e LOG_IGNORE_PATH="^\/ping|^\/health|^\/metrics" --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:testing
294+
sleep 5
295+
curl -s -k -X POST -d "banana" https://localhost:8443/metrics > /dev/null
296+
297+
if [ $(docker logs http-echo-tests | wc -l) == 2 ] && \
298+
! [ $(docker logs http-echo-tests | grep banana) ]
299+
then
300+
passed "LOG_IGNORE_PATH ignored the /metrics path"
301+
else
302+
failed "LOG_IGNORE_PATH failed"
303+
docker logs http-echo-tests
304+
exit 1
305+
fi
306+
307+
# Test a positive case where the path is not ignored
308+
curl -s -k -X POST -d "strawberry" https://localhost:8443/veryvisible > /dev/null
309+
310+
if [[ $(docker logs http-echo-tests | grep strawberry) ]]
311+
then
312+
passed "LOG_IGNORE_PATH didn't ignore the /veryvisible path"
313+
else
314+
failed "LOG_IGNORE_PATH failed, it should not ignore the /veryvisible path"
315+
docker logs http-echo-tests
316+
exit 1
317+
fi
318+
319+
288320

289321
message " Stop containers "
290322
docker stop http-echo-tests

0 commit comments

Comments
 (0)