Skip to content

Commit 3828fd0

Browse files
Fix LOG_IGNORE_PATH to also skip Morgan access logs
The LOG_IGNORE_PATH environment variable was only preventing the JSON echo output from being logged, but Morgan HTTP access logs were still being written for ignored paths. This caused the test to fail because it expected no log output for requests to /ping when LOG_IGNORE_PATH=/ping. This fix adds a skip function to the Morgan middleware that checks if the request path matches LOG_IGNORE_PATH before logging. Co-Authored-By: Willy Guggenheim <willy@gugcorp.com>
1 parent 3890f70 commit 3828fd0

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,15 @@ if(PROMETHEUS_ENABLED === 'true') {
243243
}
244244

245245
if(process.env.DISABLE_REQUEST_LOGS !== 'true'){
246-
app.use(morgan('combined'));
246+
app.use(morgan('combined', {
247+
skip: function (req, res) {
248+
// Skip logging for paths matching LOG_IGNORE_PATH
249+
if (process.env.LOG_IGNORE_PATH && new RegExp(process.env.LOG_IGNORE_PATH).test(req.path)) {
250+
return true;
251+
}
252+
return false;
253+
}
254+
}));
247255
}
248256

249257
app.use(function(req, res, next){

0 commit comments

Comments
 (0)