Comparing version 8.14.1 to 8.14.2
149
browser.js
@@ -19,3 +19,35 @@ 'use strict' | ||
} | ||
function levelToValue (level, logger) { | ||
return level === 'silent' | ||
? Infinity | ||
: logger.levels.values[level] | ||
} | ||
const baseLogFunctionSymbol = Symbol('pino.logFuncs') | ||
const hierarchySymbol = Symbol('pino.hierarchy') | ||
const logFallbackMap = { | ||
error: 'log', | ||
fatal: 'error', | ||
warn: 'error', | ||
info: 'log', | ||
debug: 'log', | ||
trace: 'log' | ||
} | ||
function appendChildLogger (parentLogger, childLogger) { | ||
const newEntry = { | ||
logger: childLogger, | ||
parent: parentLogger[hierarchySymbol] | ||
} | ||
childLogger[hierarchySymbol] = newEntry | ||
} | ||
function setupBaseLogFunctions (logger, levels, proto) { | ||
const logFunctions = {} | ||
levels.forEach(level => { | ||
logFunctions[level] = proto[level] ? proto[level] : (_console[level] || _console[logFallbackMap[level] ?? 'log'] || noop) | ||
}) | ||
logger[baseLogFunctionSymbol] = logFunctions | ||
} | ||
function shouldSerialize (serialize, serializers) { | ||
@@ -65,2 +97,6 @@ if (Array.isArray(serialize)) { | ||
setupBaseLogFunctions(logger, levels, proto) | ||
// setup root hierarchy entry | ||
appendChildLogger({}, logger) | ||
Object.defineProperty(logger, 'levelVal', { | ||
@@ -99,5 +135,3 @@ get: getLevelVal | ||
function getLevelVal () { | ||
return this.level === 'silent' | ||
? Infinity | ||
: this.levels.values[this.level] | ||
return levelToValue(this.level, this) | ||
} | ||
@@ -114,11 +148,11 @@ | ||
set(setOpts, logger, 'error', 'log') // <-- must stay first | ||
set(setOpts, logger, 'fatal', 'error') | ||
set(setOpts, logger, 'warn', 'error') | ||
set(setOpts, logger, 'info', 'log') | ||
set(setOpts, logger, 'debug', 'log') | ||
set(setOpts, logger, 'trace', 'log') | ||
set(this, setOpts, logger, 'error') // <-- must stay first | ||
set(this, setOpts, logger, 'fatal') | ||
set(this, setOpts, logger, 'warn') | ||
set(this, setOpts, logger, 'info') | ||
set(this, setOpts, logger, 'debug') | ||
set(this, setOpts, logger, 'trace') | ||
customLevels.forEach(function (level) { | ||
set(setOpts, logger, level, 'log') | ||
customLevels.forEach((level) => { | ||
set(this, setOpts, logger, level) | ||
}) | ||
@@ -146,8 +180,6 @@ } | ||
this._childLevel = (parent._childLevel | 0) + 1 | ||
this.error = bind(parent, bindings, 'error') | ||
this.fatal = bind(parent, bindings, 'fatal') | ||
this.warn = bind(parent, bindings, 'warn') | ||
this.info = bind(parent, bindings, 'info') | ||
this.debug = bind(parent, bindings, 'debug') | ||
this.trace = bind(parent, bindings, 'trace') | ||
// make sure bindings are available in the `set` function | ||
this.bindings = bindings | ||
if (childSerializers) { | ||
@@ -164,3 +196,10 @@ this.serializers = childSerializers | ||
Child.prototype = this | ||
return new Child(this) | ||
const newLogger = new Child(this) | ||
// must happen before the level is assigned | ||
appendChildLogger(this, newLogger) | ||
// required to actually initialize the logger functions for any given child | ||
newLogger.level = this.level | ||
return newLogger | ||
} | ||
@@ -212,15 +251,50 @@ return logger | ||
function set (opts, logger, level, fallback) { | ||
const proto = Object.getPrototypeOf(logger) | ||
logger[level] = logger.levelVal > logger.levels.values[level] | ||
function getBindingChain (logger) { | ||
const bindings = [] | ||
if (logger.bindings) { | ||
bindings.push(logger.bindings) | ||
} | ||
// traverse up the tree to get all bindings | ||
let hierarchy = logger[hierarchySymbol] | ||
while (hierarchy.parent) { | ||
hierarchy = hierarchy.parent | ||
if (hierarchy.logger.bindings) { | ||
bindings.push(hierarchy.logger.bindings) | ||
} | ||
} | ||
return bindings.reverse() | ||
} | ||
function set (self, opts, rootLogger, level) { | ||
// override the current log functions with either `noop` or the base log function | ||
self[level] = levelToValue(self.level, rootLogger) > levelToValue(level, rootLogger) | ||
? noop | ||
: (proto[level] ? proto[level] : (_console[level] || _console[fallback] || noop)) | ||
: rootLogger[baseLogFunctionSymbol][level] | ||
wrap(opts, logger, level) | ||
if (!opts.transmit && self[level] === noop) { | ||
return | ||
} | ||
// make sure the log format is correct | ||
self[level] = createWrap(self, opts, rootLogger, level) | ||
// prepend bindings if it is not the root logger | ||
const bindings = getBindingChain(self) | ||
if (bindings.length === 0) { | ||
// early exit in case for rootLogger | ||
return | ||
} | ||
self[level] = prependBindingsInArguments(bindings, self[level]) | ||
} | ||
function wrap (opts, logger, level) { | ||
if (!opts.transmit && logger[level] === noop) return | ||
function prependBindingsInArguments (bindings, logFunc) { | ||
return function () { | ||
return logFunc.apply(this, [...bindings, ...arguments]) | ||
} | ||
} | ||
logger[level] = (function (write) { | ||
function createWrap (self, opts, rootLogger, level) { | ||
return (function (write) { | ||
return function LOG () { | ||
@@ -239,5 +313,5 @@ const ts = opts.timestamp() | ||
if (opts.transmit) { | ||
const transmitLevel = opts.transmit.level || logger.level | ||
const transmitValue = logger.levels.values[transmitLevel] | ||
const methodValue = logger.levels.values[level] | ||
const transmitLevel = opts.transmit.level || self._level | ||
const transmitValue = rootLogger.levels.values[transmitLevel] | ||
const methodValue = rootLogger.levels.values[level] | ||
if (methodValue < transmitValue) return | ||
@@ -249,9 +323,9 @@ transmit(this, { | ||
transmitLevel, | ||
transmitValue: logger.levels.values[opts.transmit.level || logger.level], | ||
transmitValue: rootLogger.levels.values[opts.transmit.level || self._level], | ||
send: opts.transmit.send, | ||
val: logger.levelVal | ||
val: levelToValue(self._level, rootLogger) | ||
}, args) | ||
} | ||
} | ||
})(logger[level]) | ||
})(self[baseLogFunctionSymbol][level]) | ||
} | ||
@@ -295,13 +369,2 @@ | ||
function bind (parent, bindings, level) { | ||
return function () { | ||
const args = new Array(1 + arguments.length) | ||
args[0] = bindings | ||
for (var i = 1; i < args.length; i++) { | ||
args[i] = arguments[i - 1] | ||
} | ||
return parent[level].apply(this, args) | ||
} | ||
} | ||
function transmit (logger, opts, args) { | ||
@@ -308,0 +371,0 @@ const send = opts.send |
@@ -340,3 +340,3 @@ # Transports | ||
{ target: '/absolute/path/to/my-transport.mjs', level: 'error' }, | ||
{ target: 'some-file-transport', options: { destination: '/dev/null' } | ||
{ target: 'some-file-transport', options: { destination: '/dev/null' } } | ||
] | ||
@@ -402,2 +402,3 @@ }) | ||
+ [pino-datadog-transport](#pino-datadog-transport) | ||
+ [pino-slack-webhook](#pino-slack-webhook) | ||
@@ -913,2 +914,25 @@ ### Legacy | ||
<a id="pino-slack-webhook"></a> | ||
### pino-slack-webhook | ||
[pino-slack-webhook][pino-slack-webhook] is a Pino v7+ compatible transport to forward log events to [Slack][Slack] | ||
from a dedicated worker: | ||
```js | ||
const pino = require('pino') | ||
const transport = pino.transport({ | ||
target: '@youngkiu/pino-slack-webhook', | ||
options: { | ||
webhookUrl: 'https://hooks.slack.com/services/xxx/xxx/xxx', | ||
channel: '#pino-log', | ||
username: 'webhookbot', | ||
icon_emoji: ':ghost:' | ||
} | ||
}) | ||
pino(transport) | ||
``` | ||
[pino-slack-webhook]: https://github.com/youngkiu/pino-slack-webhook | ||
[Slack]: https://slack.com/ | ||
[pino-pretty]: https://github.com/pinojs/pino-pretty | ||
@@ -915,0 +939,0 @@ |
'use strict' | ||
module.exports = { version: '8.14.1' } | ||
module.exports = { version: '8.14.2' } |
@@ -23,2 +23,3 @@ 'use strict' | ||
errorKeySym, | ||
messageKeySym, | ||
useOnlyCustomLevelsSym, | ||
@@ -185,2 +186,3 @@ needsMetadataGsym, | ||
const errorKey = this[errorKeySym] | ||
const messageKey = this[messageKeySym] | ||
const mixinMergeStrategy = this[mixinMergeStrategySym] || defaultMixinMergeStrategy | ||
@@ -198,3 +200,3 @@ let obj | ||
obj = _obj | ||
if (msg === undefined && _obj.msg === undefined && _obj[errorKey]) { | ||
if (msg === undefined && _obj[messageKey] === undefined && _obj[errorKey]) { | ||
msg = _obj[errorKey].message | ||
@@ -201,0 +203,0 @@ } |
@@ -5,3 +5,3 @@ 'use strict' | ||
const getCallers = require('./caller') | ||
const { join, isAbsolute } = require('path') | ||
const { join, isAbsolute, sep } = require('path') | ||
const sleep = require('atomic-sleep') | ||
@@ -132,3 +132,7 @@ const onExit = require('on-exit-leak-free') | ||
try { | ||
fixTarget = createRequire(filePath).resolve(origin) | ||
const context = filePath === 'node:repl' | ||
? process.cwd() + sep | ||
: filePath | ||
fixTarget = createRequire(context).resolve(origin) | ||
break | ||
@@ -135,0 +139,0 @@ } catch (err) { |
{ | ||
"name": "pino", | ||
"version": "8.14.1", | ||
"version": "8.14.2", | ||
"description": "super fast, all natural json logger", | ||
@@ -64,7 +64,7 @@ "main": "pino.js", | ||
"@types/flush-write-stream": "^1.0.0", | ||
"@types/node": "^18.0.0", | ||
"@types/node": "^20.2.3", | ||
"@types/tap": "^15.0.6", | ||
"airtap": "4.0.4", | ||
"benchmark": "^2.1.4", | ||
"bole": "^4.0.0", | ||
"bole": "^5.0.5", | ||
"bunyan": "^1.8.14", | ||
@@ -76,3 +76,3 @@ "debug": "^4.3.4", | ||
"eslint-plugin-import": "^2.26.0", | ||
"eslint-plugin-n": "^15.2.2", | ||
"eslint-plugin-n": "15.7.0", | ||
"eslint-plugin-node": "^11.1.0", | ||
@@ -87,8 +87,8 @@ "eslint-plugin-promise": "^6.0.0", | ||
"loglevel": "^1.6.7", | ||
"midnight-smoker": "^2.0.1", | ||
"pino-pretty": "^9.0.0", | ||
"midnight-smoker": "1.1.1", | ||
"pino-pretty": "^10.0.0", | ||
"pre-commit": "^1.2.2", | ||
"proxyquire": "^2.1.3", | ||
"pump": "^3.0.0", | ||
"rimraf": "^4.0.7", | ||
"rimraf": "^5.0.1", | ||
"semver": "^7.3.7", | ||
@@ -103,3 +103,3 @@ "split2": "^4.0.0", | ||
"tsd": "^0.24.1", | ||
"typescript": "^4.8.2", | ||
"typescript": "^5.1.3", | ||
"winston": "^3.7.2" | ||
@@ -106,0 +106,0 @@ }, |
@@ -379,1 +379,21 @@ 'use strict' | ||
}) | ||
test('considers messageKey when giving msg precedence over error', async ({ same }) => { | ||
const err = new Error('myerror') | ||
const stream = sink() | ||
const instance = pino({ messageKey: 'message' }, stream) | ||
instance.error({ message: 'my message', err }) | ||
const result = await once(stream, 'data') | ||
delete result.time | ||
same(result, { | ||
pid, | ||
hostname, | ||
level: 50, | ||
err: { | ||
type: 'Error', | ||
stack: err.stack, | ||
message: err.message | ||
}, | ||
message: 'my message' | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
677311
190
13230