@antora/logger
Advanced tools
Comparing version 3.0.0-beta.2 to 3.0.0-beta.3
@@ -9,6 +9,6 @@ 'use strict' | ||
levels: { labels: levelLabels, values: levelValues }, | ||
symbols: { serializersSym, streamSym }, | ||
symbols: { serializersSym: $serializers, streamSym: $stream }, | ||
pino, | ||
} = require('pino') | ||
const pinoPretty = require('pino-pretty') | ||
const { default: pinoPretty, prettyFactory } = require('pino-pretty') | ||
const SonicBoom = require('sonic-boom') | ||
@@ -27,3 +27,3 @@ | ||
if (rootLogger.closed) return | ||
const dest = Object.assign(rootLogger, closedLogger)[streamSym].stream || rootLogger[streamSym] | ||
const dest = Object.assign(rootLogger, closedLogger)[$stream].stream || rootLogger[$stream] | ||
if (dest instanceof EventEmitter && typeof dest.end === 'function') { | ||
@@ -46,3 +46,3 @@ if (!(dest.fd in standardStreams)) { | ||
const prettyPrint = format === 'pretty' | ||
let colorize | ||
let colorize = process.env.NO_COLOR == null && prettyFactory()({ msg: 'colorize' }).includes('\u001b[') | ||
if (typeof (destination || (destination = {})).write !== 'function') { | ||
@@ -54,5 +54,5 @@ let dest | ||
dest = expandPath(file, { dot: baseDir }) | ||
colorize = false | ||
} else if (prettyPrint) { | ||
dest = dest || 2 | ||
if (process.env.NODE_ENV !== 'test') colorize = true | ||
} | ||
@@ -72,9 +72,7 @@ destOpts.dest = dest || 1 | ||
if (arg0 instanceof Error) { | ||
const { message, ...err } = this[serializersSym].err(arg0) | ||
args[0] = Object.assign(err, { type: 'Error' }) | ||
if (message && args[1] === undefined) args[1] = message | ||
} else if (arg0.constructor === Object) { | ||
reshapeErrorForLog(arg0, args[1], prettyPrint && this[$serializers].err).forEach((v, i) => (args[i] = v)) | ||
} else if (arg0.constructor === Object && typeof arg0.file === 'object') { | ||
const { file, line, stack, ...obj } = arg0 | ||
// NOTE assume file key is a file.src object | ||
args[0] = file ? Object.assign(obj, reshapeFileForLog(arg0)) : obj | ||
args[0] = Object.assign(obj, reshapeFileForLog(arg0)) | ||
} | ||
@@ -87,7 +85,7 @@ method.apply(this, args) | ||
if (prettyPrint) { | ||
;(logger = pino(config, createPrettyDestination(destination, colorize)))[streamSym].stream = destination | ||
;(logger = pino(config, createPrettyDestination(destination, colorize)))[$stream].stream = destination | ||
} else { | ||
logger = pino(config, destination) | ||
} | ||
logger[streamSym].flushSync = logger.silent // we do our own flush | ||
logger[$stream].flushSync = logger.silent // we do our own flush | ||
} | ||
@@ -104,3 +102,3 @@ rootLoggerHolder.set(undefined, addFailOnExitHooks(logger, failureLevel)) | ||
if ((this.ownRootLogger = rootLoggerHolder.get() || closedLogger).closed) { | ||
;(this.ownRootLogger = configure().get(null)).warn( | ||
;(this.ownRootLogger = configure({ format: 'pretty' }).get(null)).warn( | ||
'logger not configured; creating logger with default settings' | ||
@@ -131,2 +129,3 @@ ) | ||
destination, | ||
colorize, | ||
customPrettifiers: { | ||
@@ -160,7 +159,36 @@ file: ({ path: path_, line }) => (line == null ? path_ : `${path_}:${line}`), | ||
}, | ||
ignore: 'hint', | ||
messageFormat: (log, msgKey) => { | ||
let hint, msg | ||
if (typeof (msg = log[msgKey]) !== 'string') return | ||
if ((hint = log.hint)) msg += '\n' + (colorize ? `\x1b[2m${hint}\x1b[22m` : hint) | ||
if (colorize) msg = msg.replace('\n', '\n\x1b[0m') | ||
return msg | ||
}, | ||
translateTime: 'SYS:HH:MM:ss.l', // Q: do we really need ms? should we honor DATE_FORMAT env var? | ||
...(colorize ? undefined : { colorize: false }), | ||
}) | ||
} | ||
function reshapeErrorForLog (err, msg, prettyPrint, serialize) { | ||
const { name, message } = err | ||
let stack | ||
if ({}.propertyIsEnumerable.call(err, 'name')) Object.defineProperty(err, 'name', { enumerable: false }) | ||
if (msg === undefined) msg = message | ||
if (message && message === msg) err.message = undefined | ||
if ((stack = err.backtrace)) { | ||
stack = ['Error', ...stack.slice(1)].join('\n') | ||
} else if ((stack = err.stack || name) && err instanceof SyntaxError && stack.includes('\nSyntaxError: ')) { | ||
stack = `SyntaxError: ${message}\n at ` + stack.split(/\n+SyntaxError: [^\n]+\n?/).join('\n') | ||
} | ||
if (message && (message === msg || !prettyPrint) && stack.startsWith(`${name}: ${message}`)) { | ||
stack = stack.replace(`${name}: ${message}`, name) | ||
} | ||
err.stack = (prettyPrint ? 'Cause: ' : '') + (stack === name ? `${name} (no stacktrace)` : stack) | ||
if (prettyPrint) { | ||
const { message: _discard, ...flatErr } = prettyPrint(err) | ||
err = Object.assign(flatErr, { type: 'Error' }) | ||
} | ||
return [err, msg] | ||
} | ||
function reshapeFileForLog ({ file: { abspath, origin, path: vpath }, line, stack }) { | ||
@@ -167,0 +195,0 @@ if (origin) { |
{ | ||
"name": "@antora/logger", | ||
"version": "3.0.0-beta.2", | ||
"version": "3.0.0-beta.3", | ||
"description": "The logger for Antora.", | ||
@@ -19,3 +19,3 @@ "license": "MPL-2.0", | ||
"@antora/expand-path-helper": "~2.0", | ||
"pino": "~7.2", | ||
"pino": "~7.4", | ||
"pino-pretty": "~7.2", | ||
@@ -39,3 +39,3 @@ "sonic-boom": "~2.3" | ||
], | ||
"gitHead": "5cd3f9cc70622e465cb44daf1aa2035ed5a35f54" | ||
"gitHead": "45da95a2e2dea538379d2d9f42013d2208fb86c3" | ||
} |
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
29022
259
+ Addedpino@7.4.1(transitive)
- Removedpino@7.2.0(transitive)
Updatedpino@~7.4