@dotcom-reliability-kit/logger
Advanced tools
Comparing version 2.3.0 to 2.3.1
@@ -36,3 +36,3 @@ export = Logger; | ||
warn: (...args: any) => any; | ||
flush?: (() => {}) | undefined; | ||
flush?: (() => void) | undefined; | ||
}; | ||
@@ -39,0 +39,0 @@ type LogData = string | object | Error; |
@@ -57,3 +57,3 @@ const pino = require('pino').default; | ||
* Log warn level information. | ||
* @property {() => {}} [flush] | ||
* @property {() => void} [flush] | ||
* Flush async logs ahead of time. | ||
@@ -97,27 +97,13 @@ */ | ||
/** | ||
* Whether log prettification is available. This is based | ||
* on two things: the pino-pretty module being installed | ||
* in the application, and the `NODE_ENV` environment | ||
* variable being undefined or "development". | ||
* We have to try/catch here to be sure that we don't | ||
* error if pino-pretty (an optional peer dependency) | ||
* is not installed. | ||
* | ||
* @type {boolean} | ||
* @type {null | import('pino-pretty').default} | ||
*/ | ||
const PRETTIFICATION_AVAILABLE = (() => { | ||
const pinoPretty = (() => { | ||
try { | ||
// We have to `require` here rather than `require.resolve` | ||
// which is less than ideal but otherwise this is actually | ||
// impossible to test with Jest. Both technically do the | ||
// same file system work though, and it's only done once | ||
// when the module first loads. It's also safe to ts-ignore | ||
// this one because it's never actually used directly. | ||
// @ts-ignore | ||
require('pino-pretty'); | ||
// If we get to this point, pino-pretty is installed because | ||
// otherwise it would have errored. So we can just check for | ||
// the environment not being "production" (which implies | ||
// "development", "test" or a similar pre-production term). | ||
return appInfo.environment !== 'production'; | ||
return require('pino-pretty').default; | ||
} catch (_) { | ||
return false; | ||
return null; | ||
} | ||
@@ -127,2 +113,11 @@ })(); | ||
/** | ||
* Whether log prettification is allowed. We never allow log | ||
* prettification if the `NODE_ENV` environment variable is | ||
* set to "production". | ||
* | ||
* @type {boolean} | ||
*/ | ||
const prettificationAllowed = appInfo.environment !== 'production'; | ||
/** | ||
* Class representing a logger. | ||
@@ -222,12 +217,13 @@ */ | ||
}; | ||
if (withPrettifier && PRETTIFICATION_AVAILABLE) { | ||
pinoOptions.transport = { | ||
target: 'pino-pretty', | ||
options: { | ||
if (withPrettifier && prettificationAllowed && pinoPretty) { | ||
this.#logTransport = pino( | ||
pinoOptions, | ||
pinoPretty({ | ||
colorize: true, | ||
messageKey: 'message' | ||
} | ||
}; | ||
}) | ||
); | ||
} else { | ||
this.#logTransport = pino(pinoOptions); | ||
} | ||
this.#logTransport = pino(pinoOptions); | ||
this.#logTransport.level = this.#logLevel; | ||
@@ -234,0 +230,0 @@ } |
{ | ||
"name": "@dotcom-reliability-kit/logger", | ||
"version": "2.3.0", | ||
"version": "2.3.1", | ||
"description": "A simple and fast logger based on Pino, with FT preferences baked in", | ||
@@ -22,3 +22,3 @@ "repository": { | ||
"lodash.clonedeep": "^4.5.0", | ||
"pino": "^8.15.1" | ||
"pino": "^8.16.2" | ||
}, | ||
@@ -25,0 +25,0 @@ "peerDependencies": { |
Sorry, the diff of this file is not supported yet
48889
814
Updatedpino@^8.16.2