pino-pretty
Advanced tools
Comparing version 4.0.0 to 4.0.1
@@ -37,5 +37,5 @@ #!/usr/bin/env node | ||
.option(['f', 'crlf'], 'Append CRLF instead of LF to formatted lines') | ||
.option(['e', 'errorProps'], 'Comma separated list of properties on error objects to show (`*` for all properties)', '') | ||
.option(['e', 'errorProps'], 'Comma separated list of properties on error objects to show (`*` for all properties) (defaults to ``)') | ||
.option(['l', 'levelFirst'], 'Display the log level as the first output field') | ||
.option(['k', 'errorLikeObjectKeys'], 'Define which keys contain error objects (`-k err,error`)', 'err,error') | ||
.option(['k', 'errorLikeObjectKeys'], 'Define which keys contain error objects (`-k err,error`) (defaults to `err,error`)') | ||
.option(['m', 'messageKey'], 'Highlight the message under the specified key', CONSTANTS.MESSAGE_KEY) | ||
@@ -79,2 +79,5 @@ .option('levelKey', 'Detect the log level under the specified key', CONSTANTS.LEVEL_KEY) | ||
opts = Object.assign({}, config, opts) | ||
// set defaults | ||
opts.errorLikeObjectKeys = opts.errorLikeObjectKeys || 'err,error' | ||
opts.errorProps = opts.errorProps || '' | ||
const pretty = prettyFactory(opts) | ||
@@ -81,0 +84,0 @@ const prettyTransport = new Transform({ |
@@ -77,2 +77,3 @@ 'use strict' | ||
const prettifiedMessage = prettifyMessage({ log, messageKey, colorizer, messageFormat }) | ||
const prettifiedTime = prettifyTime({ log, translateFormat: opts.translateTime, timestampKey }) | ||
@@ -90,3 +91,2 @@ if (ignoreKeys) { | ||
const prettifiedMetadata = prettifyMetadata({ log }) | ||
const prettifiedTime = prettifyTime({ log, translateFormat: opts.translateTime, timestampKey }) | ||
@@ -93,0 +93,0 @@ let line = '' |
{ | ||
"name": "pino-pretty", | ||
"version": "4.0.0", | ||
"version": "4.0.1", | ||
"description": "Prettifier for Pino log lines", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -646,3 +646,17 @@ 'use strict' | ||
t.test('handles specified timestampKey', (t) => { | ||
t.plan(1) | ||
const pretty = prettyFactory({ timestampKey: '@timestamp' }) | ||
const arst = pretty(`{"msg":"hello world", "@timestamp":${epoch}, "level":30}`) | ||
t.is(arst, `[${epoch}] INFO : hello world\n @timestamp: ${epoch}\n`) | ||
}) | ||
t.test('handles using ignored timestampKey', (t) => { | ||
t.plan(1) | ||
const pretty = prettyFactory({ timestampKey: '@timestamp', ignore: '@timestamp' }) | ||
const arst = pretty(`{"msg":"hello world", "@timestamp":${epoch}, "level":30}`) | ||
t.is(arst, `[${epoch}] INFO : hello world\n`) | ||
}) | ||
t.end() | ||
}) |
@@ -133,2 +133,26 @@ 'use strict' | ||
t.test('cli options with defaults can be overridden by config', (t) => { | ||
t.plan(1) | ||
// Set errorProps: '*' on run configuration | ||
const configFile = path.join(tmpDir, 'pino-pretty.config.js') | ||
fs.writeFileSync(configFile, ` | ||
module.exports = { | ||
errorProps: '*' | ||
} | ||
`.trim()) | ||
// Set messageKey: 'new_msg' using command line option | ||
const env = { TERM: 'dumb' } | ||
const child = spawn(process.argv[0], [bin], { env, cwd: tmpDir }) | ||
// Validate that the time has been translated and correct message key has been used | ||
child.on('error', t.threw) | ||
child.stdout.on('data', (data) => { | ||
t.is(data.toString(), '[1594416696006] FATAL: There was an error starting the process.\n QueryError: Error during sql query: syntax error at or near SELECTT\n at /home/me/projects/example/sql.js\n at /home/me/projects/example/index.js\nquerySql: SELECTT * FROM "test" WHERE id = $1;\nqueryArgs: 12\n') | ||
}) | ||
child.stdin.write('{"level":60,"time":1594416696006,"msg":"There was an error starting the process.","type":"Error","stack":"QueryError: Error during sql query: syntax error at or near SELECTT\\n at /home/me/projects/example/sql.js\\n at /home/me/projects/example/index.js","querySql":"SELECTT * FROM \\"test\\" WHERE id = $1;","queryArgs":[12]}\n') | ||
t.tearDown(() => { | ||
fs.unlinkSync(configFile) | ||
child.kill() | ||
}) | ||
}) | ||
t.test('throws on missing config file', (t) => { | ||
@@ -135,0 +159,0 @@ t.plan(2) |
@@ -103,3 +103,29 @@ 'use strict' | ||
t.test('uses specified timestampKey', (t) => { | ||
t.plan(1) | ||
const env = { TERM: 'dumb' } | ||
const child = spawn(process.argv[0], [bin, '--timestampKey', '@timestamp'], { env }) | ||
child.on('error', t.threw) | ||
child.stdout.on('data', (data) => { | ||
t.is(data.toString(), '[1522431328992] INFO : hello world\n @timestamp: 1522431328992\n') | ||
}) | ||
const logLine = '{"level":30,"@timestamp":1522431328992,"msg":"hello world"}\n' | ||
child.stdin.write(logLine) | ||
t.tearDown(() => child.kill()) | ||
}) | ||
t.test('uses an ignored timestampKey', (t) => { | ||
t.plan(1) | ||
const env = { TERM: 'dumb' } | ||
const child = spawn(process.argv[0], [bin, '--timestampKey', '@timestamp', '--ignore', '@timestamp'], { env }) | ||
child.on('error', t.threw) | ||
child.stdout.on('data', (data) => { | ||
t.is(data.toString(), '[1522431328992] INFO : hello world\n') | ||
}) | ||
const logLine = '{"level":30,"@timestamp":1522431328992,"msg":"hello world"}\n' | ||
child.stdin.write(logLine) | ||
t.tearDown(() => child.kill()) | ||
}) | ||
t.end() | ||
}) |
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
268422
21
2191