-
Notifications
You must be signed in to change notification settings - Fork 846
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove deprecated API and options in v7 option. #1249
Changes from 2 commits
e52aa16
f6528be
b3807e6
011e7e9
1f77fb5
8efe852
9f28c81
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,6 @@ | |
const warning = require('fastify-warning')() | ||
module.exports = warning | ||
|
||
const warnName = 'PinoWarning' | ||
// const warnName = 'PinoWarning' | ||
|
||
warning.create(warnName, 'PINODEP008', 'prettyPrint is deprecated, look at https://github.com/pinojs/pino-pretty for alternatives.') | ||
|
||
warning.create(warnName, 'PINODEP009', 'The use of pino.final is discouraged in Node.js v14+ and not required. It will be removed in the next major version') | ||
// warning.create(warnName, 'PINODEP010', 'A new deprecation') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. stray comment? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is on purpose to avoid deleting this file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is the file needed? if not we should remove it - if we ever need it again it's in the commit history right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's easier to keep it and update it as necessary. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,11 +5,10 @@ | |
const format = require('quick-format-unescaped') | ||
const { mapHttpRequest, mapHttpResponse } = require('pino-std-serializers') | ||
const SonicBoom = require('sonic-boom') | ||
const warning = require('./deprecations') | ||
const onExit = require('on-exit-leak-free') | ||
const { | ||
lsCacheSym, | ||
chindingsSym, | ||
parsedChindingsSym, | ||
writeSym, | ||
serializersSym, | ||
formatOptsSym, | ||
|
@@ -18,9 +17,6 @@ const { | |
stringifySym, | ||
stringifySafeSym, | ||
wildcardFirstSym, | ||
needsMetadataGsym, | ||
redactFmtSym, | ||
streamSym, | ||
nestedKeySym, | ||
formattersSym, | ||
messageKeySym, | ||
|
@@ -211,123 +207,6 @@ function asChindings (instance, bindings) { | |
return data | ||
} | ||
|
||
function getPrettyStream (opts, prettifier, dest, instance) { | ||
if (prettifier && typeof prettifier === 'function') { | ||
prettifier = prettifier.bind(instance) | ||
return prettifierMetaWrapper(prettifier(opts), dest, opts) | ||
} | ||
try { | ||
const prettyFactory = require('pino-pretty').prettyFactory | ||
prettyFactory.asMetaWrapper = prettifierMetaWrapper | ||
return prettifierMetaWrapper(prettyFactory(opts), dest, opts) | ||
} catch (e) { | ||
if (e.message.startsWith("Cannot find module 'pino-pretty'")) { | ||
throw Error('Missing `pino-pretty` module: `pino-pretty` must be installed separately') | ||
}; | ||
throw e | ||
} | ||
} | ||
|
||
function prettifierMetaWrapper (pretty, dest, opts) { | ||
opts = Object.assign({ suppressFlushSyncWarning: false }, opts) | ||
let warned = false | ||
return { | ||
[needsMetadataGsym]: true, | ||
lastLevel: 0, | ||
lastMsg: null, | ||
lastObj: null, | ||
lastLogger: null, | ||
flushSync () { | ||
if (opts.suppressFlushSyncWarning || warned) { | ||
return | ||
} | ||
warned = true | ||
setMetadataProps(dest, this) | ||
dest.write(pretty(Object.assign({ | ||
level: 40, // warn | ||
msg: 'pino.final with prettyPrint does not support flushing', | ||
time: Date.now() | ||
}, this.chindings()))) | ||
}, | ||
chindings () { | ||
const lastLogger = this.lastLogger | ||
let chindings = null | ||
|
||
// protection against flushSync being called before logging | ||
// anything | ||
if (!lastLogger) { | ||
return null | ||
} | ||
|
||
if (lastLogger.hasOwnProperty(parsedChindingsSym)) { | ||
chindings = lastLogger[parsedChindingsSym] | ||
} else { | ||
chindings = JSON.parse('{' + lastLogger[chindingsSym].substr(1) + '}') | ||
lastLogger[parsedChindingsSym] = chindings | ||
} | ||
|
||
return chindings | ||
}, | ||
write (chunk) { | ||
const lastLogger = this.lastLogger | ||
const chindings = this.chindings() | ||
|
||
let time = this.lastTime | ||
|
||
/* istanbul ignore next */ | ||
if (typeof time === 'number') { | ||
// do nothing! | ||
} else if (time.match(/^\d+/)) { | ||
time = parseInt(time) | ||
} else { | ||
time = time.slice(1, -1) | ||
} | ||
|
||
const lastObj = this.lastObj | ||
const lastMsg = this.lastMsg | ||
const errorProps = null | ||
|
||
const formatters = lastLogger[formattersSym] | ||
const formattedObj = formatters.log ? formatters.log(lastObj) : lastObj | ||
|
||
const messageKey = lastLogger[messageKeySym] | ||
if (lastMsg && formattedObj && !formattedObj.hasOwnProperty(messageKey)) { | ||
formattedObj[messageKey] = lastMsg | ||
} | ||
|
||
const obj = Object.assign({ | ||
level: this.lastLevel, | ||
time | ||
}, formattedObj, errorProps) | ||
|
||
const serializers = lastLogger[serializersSym] | ||
const keys = Object.keys(serializers) | ||
|
||
for (var i = 0; i < keys.length; i++) { | ||
const key = keys[i] | ||
if (obj[key] !== undefined) { | ||
obj[key] = serializers[key](obj[key]) | ||
} | ||
} | ||
|
||
for (const key in chindings) { | ||
if (!obj.hasOwnProperty(key)) { | ||
obj[key] = chindings[key] | ||
} | ||
} | ||
|
||
const stringifiers = lastLogger[stringifiersSym] | ||
const redact = stringifiers[redactFmtSym] | ||
|
||
const formatted = pretty(typeof redact === 'function' ? redact(obj) : obj) | ||
if (formatted === undefined) return | ||
|
||
setMetadataProps(dest, this) | ||
dest.write(formatted) | ||
} | ||
} | ||
} | ||
|
||
function hasBeenTampered (stream) { | ||
return stream.write !== stream.constructor.prototype.write | ||
} | ||
|
@@ -337,12 +216,17 @@ function buildSafeSonicBoom (opts) { | |
stream.on('error', filterBrokenPipe) | ||
// if we are sync: false, we must flush on exit | ||
if (!opts.sync && isMainThread) { | ||
setupOnExit(stream) | ||
onExit.register(stream, autoEnd) | ||
|
||
stream.on('close', function () { | ||
onExit.unregister(stream) | ||
}) | ||
} | ||
return stream | ||
|
||
function filterBrokenPipe (err) { | ||
// TODO verify on Windows | ||
// Impossible to replicate across all operating systems | ||
/* istanbul ignore next */ | ||
if (err.code === 'EPIPE') { | ||
// If we get EPIPE, we should stop logging here | ||
// however we have no control to the consumer of | ||
|
@@ -358,20 +242,6 @@ function buildSafeSonicBoom (opts) { | |
} | ||
} | ||
|
||
function setupOnExit (stream) { | ||
/* istanbul ignore next */ | ||
if (global.WeakRef && global.WeakMap && global.FinalizationRegistry) { | ||
// This is leak free, it does not leave event handlers | ||
const onExit = require('on-exit-leak-free') | ||
|
||
onExit.register(stream, autoEnd) | ||
|
||
stream.on('close', function () { | ||
onExit.unregister(stream) | ||
}) | ||
} | ||
} | ||
|
||
function autoEnd (stream, eventName) { | ||
// This check is needed only on some platforms | ||
/* istanbul ignore next */ | ||
|
@@ -386,6 +256,8 @@ function autoEnd (stream, eventName) { | |
stream.end() | ||
}) | ||
} else { | ||
// For some reason istanbul is not detecting this, but it's there | ||
/* istanbul ignore next */ | ||
mcollina marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// We do not have an event loop, so flush synchronously | ||
stream.flushSync() | ||
} | ||
|
@@ -410,85 +282,19 @@ function createArgsNormalizer (defaultOptions) { | |
} | ||
opts = Object.assign({}, defaultOptions, opts) | ||
opts.serializers = Object.assign({}, defaultOptions.serializers, opts.serializers) | ||
if ('onTerminated' in opts) { | ||
throw Error('The onTerminated option has been removed, use pino.final instead') | ||
} | ||
if ('changeLevelName' in opts) { | ||
process.emitWarning( | ||
'The changeLevelName option is deprecated and will be removed in v7. Use levelKey instead.', | ||
{ code: 'changeLevelName_deprecation' } | ||
) | ||
opts.levelKey = opts.changeLevelName | ||
delete opts.changeLevelName | ||
if (opts.prettyPrint) { | ||
throw new Error('prettyPrint option is no longer supported, see the pino-pretty package.') | ||
} | ||
const { enabled, prettyPrint, prettifier, messageKey } = opts | ||
const { enabled } = opts | ||
if (enabled === false) opts.level = 'silent' | ||
stream = stream || process.stdout | ||
if (stream === process.stdout && stream.fd >= 0 && !hasBeenTampered(stream)) { | ||
stream = buildSafeSonicBoom({ fd: stream.fd, sync: true }) | ||
} | ||
if (prettyPrint) { | ||
warning.emit('PINODEP008') | ||
const prettyOpts = Object.assign({ messageKey }, prettyPrint) | ||
stream = getPrettyStream(prettyOpts, prettifier, stream, instance) | ||
} | ||
return { opts, stream } | ||
} | ||
} | ||
|
||
function final (logger, handler) { | ||
const major = Number(process.versions.node.split('.')[0]) | ||
if (major >= 14) warning.emit('PINODEP009') | ||
|
||
if (typeof logger === 'undefined' || typeof logger.child !== 'function') { | ||
throw Error('expected a pino logger instance') | ||
} | ||
const hasHandler = (typeof handler !== 'undefined') | ||
if (hasHandler && typeof handler !== 'function') { | ||
throw Error('if supplied, the handler parameter should be a function') | ||
} | ||
const stream = logger[streamSym] | ||
if (typeof stream.flushSync !== 'function') { | ||
throw Error('final requires a stream that has a flushSync method, such as pino.destination') | ||
} | ||
|
||
const finalLogger = new Proxy(logger, { | ||
get: (logger, key) => { | ||
if (key in logger.levels.values) { | ||
return (...args) => { | ||
logger[key](...args) | ||
stream.flushSync() | ||
} | ||
} | ||
return logger[key] | ||
} | ||
}) | ||
|
||
if (!hasHandler) { | ||
try { | ||
stream.flushSync() | ||
} catch { | ||
// it's too late to wait for the stream to be ready | ||
// because this is a final tick scenario. | ||
// in practice there shouldn't be a situation where it isn't | ||
// however, swallow the error just in case (and for easier testing) | ||
} | ||
return finalLogger | ||
} | ||
|
||
return (err = null, ...args) => { | ||
try { | ||
stream.flushSync() | ||
} catch (e) { | ||
// it's too late to wait for the stream to be ready | ||
// because this is a final tick scenario. | ||
// in practice there shouldn't be a situation where it isn't | ||
// however, swallow the error just in case (and for easier testing) | ||
} | ||
return handler(err, finalLogger, ...args) | ||
} | ||
} | ||
|
||
function stringify (obj, stringifySafeFn) { | ||
try { | ||
return JSON.stringify(obj) | ||
|
@@ -510,16 +316,6 @@ function buildFormatters (level, bindings, log) { | |
} | ||
} | ||
|
||
function setMetadataProps (dest, that) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. love to see this go |
||
if (dest[needsMetadataGsym] === true) { | ||
dest.lastLevel = that.lastLevel | ||
dest.lastMsg = that.lastMsg | ||
dest.lastObj = that.lastObj | ||
dest.lastTime = that.lastTime | ||
dest.lastLogger = that.lastLogger | ||
} | ||
} | ||
|
||
/** | ||
* Convert a string integer file descriptor to a proper native integer | ||
* file descriptor. | ||
|
@@ -539,12 +335,10 @@ function normalizeDestFileDescriptor (destination) { | |
module.exports = { | ||
noop, | ||
buildSafeSonicBoom, | ||
getPrettyStream, | ||
asChindings, | ||
asJson, | ||
genLog, | ||
createArgsNormalizer, | ||
final, | ||
stringify, | ||
buildFormatters, | ||
normalizeDestFileDescriptor | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this file required anywhere else now? if not, remove?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll definitely need it at some point in the future, better to keep.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for me it's a loose end - maybe this whole concept should be a separate module or something