-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add log metadata functions + Remove testing ignore flag + Update documentation + Update pino version to latest version
- Loading branch information
1 parent
83ce703
commit 8639507
Showing
10 changed files
with
2,704 additions
and
2,099 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
language: node_js | ||
node_js: | ||
- "8.11.4" | ||
- "12.17.0" | ||
dist: trusty | ||
|
||
script: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,13 @@ | ||
const { getRequestId } = require('../namespace'); | ||
|
||
const loggerOptions = ['pino']; | ||
|
||
const getRequestIdPrefix = () => { | ||
const requestId = getRequestId(); | ||
return requestId ? `[${requestId}] ` : ''; | ||
}; | ||
|
||
const isTesting = process.env.NODE_ENV && process.env.NODE_ENV.toLowerCase() === 'testing', | ||
logOnTesting = !!process.env.LOG_ON_TEST; | ||
|
||
const createLogger = opts => { | ||
const { options, loggerOption = 'pino' } = opts || {}; | ||
if (!loggerOptions.includes(loggerOption)) { | ||
throw new Error(`Logger '${loggerOption}' is not available, available loggers are [${loggerOptions}]`); | ||
} | ||
|
||
const { getLogger, getLogLevels } = require(`./${loggerOption}`); | ||
const logger = getLogger(options); | ||
const loggerWrapper = getLogLevels(logger).reduce((newLogger, logLevel) => { | ||
newLogger[logLevel] = | ||
isTesting && !logOnTesting ? () => true : (...args) => logger[logLevel](getRequestIdPrefix(), ...args); | ||
return newLogger; | ||
}, {}); | ||
|
||
return { ...logger, ...loggerWrapper }; | ||
// eslint-disable-next-line global-require | ||
const { getLogger } = require(`./${loggerOption}`); | ||
return getLogger(options); | ||
}; | ||
|
||
module.exports = { createLogger, logger: createLogger() }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
const pino = require('pino'); | ||
|
||
const defaultPinoOptions = { | ||
prettyPrint: { | ||
translateTime: true, | ||
colorize: false | ||
} | ||
}; | ||
const { getLogMetadata } = require('../namespace'); | ||
|
||
module.exports = { | ||
getLogLevels: logger => Object.keys(logger.levels.values), | ||
getLogger: (options = defaultPinoOptions) => pino(options) | ||
getLogger: (options = {}) => | ||
pino({ | ||
...options, | ||
mixin: () => getLogMetadata() | ||
}) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.