Skip to content

Commit

Permalink
fix: connectLogger nolog
Browse files Browse the repository at this point in the history
  • Loading branch information
eyoboue committed Jul 8, 2022
1 parent 4351519 commit 25eacc9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 29 deletions.
4 changes: 0 additions & 4 deletions .husky/pre-push

This file was deleted.

34 changes: 10 additions & 24 deletions lib/connect-logger.js
Expand Up @@ -208,25 +208,6 @@ function matchRules(statusCode, currentLevel, ruleSet) {
return level;
}

/**
* Log skipping check
*
* @param {IncomingMessage} req
* @param {ServerResponse} res
* @param {Array|string|RegExp|Function} nolog
* @return {boolean}
* @api private
*/
function shouldSkip(req, res, nolog) {
if (typeof nolog === 'function') {
if (nolog(req, res) === true) return true;
} else {
const regexp = createNoLogCondition(nolog);
if (regexp && regexp.test(req.originalUrl)) return true;
}
return false;
}

/**
* Log requests with the given `options` or a `format` string.
*
Expand Down Expand Up @@ -270,10 +251,13 @@ module.exports = function getLogger(logger4js, options) {

return (req, res, next) => {
// mount safety
if (req._logging) return next();
if (req._logging !== undefined) return next();

// nologs
if (shouldSkip(req, res, options.nolog)) return next();
if (typeof options.nolog !== 'function') {
const nolog = createNoLogCondition(options.nolog);
if (nolog && nolog.test(req.originalUrl)) return next();
}

if (thisLogger.isLevelEnabled(level) || options.level === 'auto') {
const start = new Date();
Expand All @@ -300,9 +284,11 @@ module.exports = function getLogger(logger4js, options) {
finished = true;

// nologs
if (shouldSkip(req, res, options.nolog)) {
req._logging = false;
return;
if (typeof options.nolog === 'function') {
if (options.nolog(req, res) === true) {
req._logging = false;
return;
}
}

res.responseTime = new Date() - start;
Expand Down
4 changes: 3 additions & 1 deletion test/tap/configuration-validation-test.js
Expand Up @@ -274,7 +274,9 @@ test('log4js configuration validation', (batch) => {
})
)
);
t.end();
log4js.shutdown(() => {
t.end();
});
});

batch.test('should load appenders from core first', (t) => {
Expand Down

0 comments on commit 25eacc9

Please sign in to comment.