@antora/logger
Advanced tools
Comparing version 3.0.0-alpha.7 to 3.0.0-alpha.8
@@ -26,7 +26,6 @@ 'use strict' | ||
if (rootLogger.closed) return | ||
const strm = Object.assign(rootLogger, closedLogger)[streamSym] | ||
if (strm instanceof EventEmitter && typeof strm.end === 'function' && (strm._buf || !(strm.fd in standardStreams))) { | ||
const waitForClose = once(strm, 'close').catch(() => undefined) | ||
strm.end() | ||
finalizers.push(waitForClose) | ||
const dest = Object.assign(rootLogger, closedLogger)[streamSym].stream || rootLogger[streamSym] | ||
if (dest instanceof EventEmitter && typeof dest.end === 'function' && (dest._buf || !(dest.fd in standardStreams))) { | ||
finalizers.push(once(dest, 'close').catch(() => undefined)) | ||
dest.end() | ||
} | ||
@@ -36,80 +35,81 @@ } | ||
function configure ({ name, level = 'info', levelFormat, failureLevel = 'silent', format, destination } = {}, baseDir) { | ||
const silent = (levelValues[level] || (level === 'all' ? (level = minLevel) : INF)) === INF | ||
if (silent && (levelValues[failureLevel] || INF) === INF && (rootLoggerHolder.get() || {}).noop) return module.exports | ||
close() | ||
const prettyPrint = format === 'pretty' | ||
let colorize, dest | ||
if (!(silent || typeof (destination || (destination = {})).write === 'function')) { | ||
const { file, append = true, bufferSize, ...destOpts } = destination | ||
if (bufferSize != null) destOpts.minLength = bufferSize | ||
if (file && !(dest = standardStreams[file])) { | ||
dest = expandPath(file, '~+', baseDir) | ||
try { | ||
fs.mkdirSync(ospath.dirname(dest), { recursive: true }) | ||
if (!append) fs.unlinkSync(dest) | ||
} catch {} | ||
} else if (process.env.NODE_ENV !== 'test') { | ||
colorize = true | ||
let logger | ||
if ((levelValues[level] || (level === 'all' ? (level = minLevel) : INF)) === INF) { | ||
if ((levelValues[failureLevel] || INF) === INF && (rootLoggerHolder.get() || {}).noop) return module.exports | ||
close() | ||
logger = Object.assign(Object.create(Object.getPrototypeOf(noopLogger)), noopLogger) | ||
} else { | ||
const prettyPrint = format === 'pretty' | ||
let colorize, dest | ||
if (typeof (destination || (destination = {})).write !== 'function') { | ||
const { file, append = true, bufferSize, ...destOpts } = destination | ||
if (bufferSize != null) destOpts.minLength = bufferSize | ||
if (file && !(dest = standardStreams[file])) { | ||
dest = expandPath(file, { dot: baseDir }) | ||
try { | ||
fs.mkdirSync(ospath.dirname(dest), { recursive: true }) | ||
if (!append) fs.unlinkSync(dest) | ||
} catch {} | ||
} else if (process.env.NODE_ENV !== 'test') { | ||
colorize = true | ||
} | ||
destination = buildDest(Object.assign({ sync: true }, destOpts, { dest: dest || (prettyPrint ? 2 : 1) })) | ||
} | ||
destination = buildDest(prettyPrint ? dest || 2 : Object.assign({ sync: true }, destOpts, { dest: dest || 1 })) | ||
} | ||
const logger = addFailOnExitHooks( | ||
silent | ||
? Object.assign(Object.create(Object.getPrototypeOf(noopLogger)), noopLogger) | ||
: pino( | ||
{ | ||
name, | ||
base: {}, | ||
level, | ||
formatters: { level: levelFormat === 'number' ? (_, level) => ({ level }) : (level) => ({ level }) }, | ||
hooks: { | ||
// NOTE logMethod only called if log level is enabled | ||
logMethod (args, method) { | ||
const arg0 = args[0] | ||
if (arg0.constructor === Object) { | ||
const { file, line, stack, ...obj } = arg0 | ||
// NOTE we assume file key is a file.src object | ||
args[0] = file ? Object.assign(obj, reshapeFileForLog(arg0)) : obj | ||
} | ||
method.apply(this, args) | ||
}, | ||
close() | ||
logger = pino( | ||
{ | ||
name, | ||
base: {}, | ||
level, | ||
formatters: { level: levelFormat === 'number' ? (_, level) => ({ level }) : (level) => ({ level }) }, | ||
hooks: { | ||
// NOTE logMethod only called if log level is enabled | ||
logMethod (args, method) { | ||
const arg0 = args[0] | ||
if (arg0.constructor === Object) { | ||
const { file, line, stack, ...obj } = arg0 | ||
// NOTE we assume file key is a file.src object | ||
args[0] = file ? Object.assign(obj, reshapeFileForLog(arg0)) : obj | ||
} | ||
method.apply(this, args) | ||
}, | ||
prettyPrint: prettyPrint && { | ||
customPrettifiers: { | ||
file: ({ path: path_, line }) => (line == null ? path_ : `${path_}:${line}`), | ||
stack: (stack, _, log) => { | ||
let prevSource = log.source | ||
return stack | ||
.map(({ file: { path: path_, line }, source }) => { | ||
const file = `${path_}:${line}` | ||
const repeatSource = | ||
prevSource && | ||
source.url === prevSource.url && | ||
source.refname === prevSource.refname && | ||
source.startPath === prevSource.startPath | ||
prevSource = source | ||
if (repeatSource) return `\n file: ${file}` | ||
const { url, worktree, refname, startPath } = source | ||
source = worktree | ||
? `${worktree} (refname: ${refname} <worktree>${startPath ? ', start path: ' + startPath : ''})` | ||
: `${url || '<unknown>'} (refname: ${refname}${startPath ? ', start path: ' + startPath : ''})` | ||
return `\n file: ${file}\n source: ${source}` | ||
}) | ||
.join('') | ||
}, | ||
source: ({ url, worktree, refname, startPath }) => | ||
worktree | ||
? `${worktree} (refname: ${refname} <worktree>${startPath ? ', start path: ' + startPath : ''})` | ||
: `${url || '<unknown>'} (refname: ${refname}${startPath ? ', start path: ' + startPath : ''})`, | ||
}, | ||
prettyPrint: prettyPrint && { | ||
customPrettifiers: { | ||
file: ({ path: path_, line }) => (line == null ? path_ : `${path_}:${line}`), | ||
stack: (stack, _, log) => { | ||
let prevSource = log.source | ||
return stack | ||
.map(({ file: { path: path_, line }, source }) => { | ||
const file = `${path_}:${line}` | ||
const repeatSource = | ||
prevSource && | ||
source.url === prevSource.url && | ||
source.refname === prevSource.refname && | ||
source.startPath === prevSource.startPath | ||
prevSource = source | ||
if (repeatSource) return `\n file: ${file}` | ||
const { url, worktree, refname, startPath } = source | ||
source = worktree | ||
? `${worktree} (refname: ${refname} <worktree>${startPath ? ', start path: ' + startPath : ''})` | ||
: `${url || '<unknown>'} (refname: ${refname}${startPath ? ', start path: ' + startPath : ''})` | ||
return `\n file: ${file}\n source: ${source}` | ||
}) | ||
.join('') | ||
}, | ||
suppressFlushSyncWarning: true, | ||
translateTime: 'SYS:HH:MM:ss.l', // Q: do we really need ms? should we honor DATE_FORMAT env var? | ||
...(colorize ? undefined : { colorize: false }), | ||
source: ({ url, worktree, refname, startPath }) => | ||
worktree | ||
? `${worktree} (refname: ${refname} <worktree>${startPath ? ', start path: ' + startPath : ''})` | ||
: `${url || '<unknown>'} (refname: ${refname}${startPath ? ', start path: ' + startPath : ''})`, | ||
}, | ||
suppressFlushSyncWarning: true, | ||
translateTime: 'SYS:HH:MM:ss.l', // Q: do we really need ms? should we honor DATE_FORMAT env var? | ||
...(colorize ? undefined : { colorize: false }), | ||
}, | ||
destination | ||
), | ||
failureLevel | ||
) | ||
rootLoggerHolder.set(undefined, logger) | ||
}, | ||
destination | ||
) | ||
if (prettyPrint) logger[streamSym].stream = destination | ||
} | ||
rootLoggerHolder.set(undefined, addFailOnExitHooks(logger, failureLevel)) | ||
return module.exports | ||
@@ -116,0 +116,0 @@ } |
{ | ||
"name": "@antora/logger", | ||
"version": "3.0.0-alpha.7", | ||
"version": "3.0.0-alpha.8", | ||
"description": "The logger for Antora.", | ||
@@ -18,3 +18,3 @@ "license": "MPL-2.0", | ||
"dependencies": { | ||
"@antora/expand-path-helper": "~1.0", | ||
"@antora/expand-path-helper": "~2.0", | ||
"pino": "~6.11", | ||
@@ -38,3 +38,3 @@ "pino-pretty": "~5.1" | ||
], | ||
"gitHead": "fbd597b3680474f2083cda8a7facf1e2848c08e0" | ||
"gitHead": "2e5695bea11fb5719989c329c97e66d36e29659f" | ||
} |
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
27270
+ Added@antora/expand-path-helper@2.0.0(transitive)
- Removed@antora/expand-path-helper@1.0.0(transitive)