pino-pretty
Advanced tools
Comparing version 6.0.0 to 7.0.0
25
bin.js
@@ -7,15 +7,14 @@ #!/usr/bin/env node | ||
const pump = require('pump') | ||
const split = require('split2') | ||
const { Transform } = require('readable-stream') | ||
const prettyFactory = require('./') | ||
const sjp = require('secure-json-parse') | ||
const JoyCon = require('joycon') | ||
const stripJsonComments = require('strip-json-comments') | ||
const build = require('./') | ||
const CONSTANTS = require('./lib/constants') | ||
const { isObject } = require('./lib/utils') | ||
const bourne = require('@hapi/bourne') | ||
const stripJsonComments = require('strip-json-comments') | ||
const parseJSON = input => { | ||
return bourne.parse(stripJsonComments(input), { protoAction: 'remove' }) | ||
return sjp.parse(stripJsonComments(input), { protoAction: 'remove' }) | ||
} | ||
const JoyCon = require('joycon') | ||
const joycon = new JoyCon({ | ||
@@ -92,13 +91,5 @@ parseJSON, | ||
opts.errorProps = opts.errorProps || '' | ||
const pretty = prettyFactory(opts) | ||
const prettyTransport = new Transform({ | ||
objectMode: true, | ||
transform (chunk, enc, cb) { | ||
const line = pretty(chunk.toString()) | ||
if (line === undefined) return cb() | ||
cb(null, line) | ||
} | ||
}) | ||
pump(process.stdin, split(), prettyTransport, process.stdout) | ||
const res = build(opts) | ||
pump(process.stdin, res) | ||
@@ -105,0 +96,0 @@ // https://github.com/pinojs/pino/pull/358 |
@@ -94,6 +94,2 @@ // Type definitions for pino-pretty 4.7 | ||
/** | ||
* Specify a search pattern according to {@link http://jmespath.org|jmespath} | ||
*/ | ||
search?: string; | ||
/** | ||
* Ignore one or several keys. | ||
@@ -100,0 +96,0 @@ * @example "time,hostname" |
52
index.js
'use strict' | ||
const { options: coloretteOptions } = require('colorette') | ||
const jmespath = require('jmespath') | ||
const pump = require('pump') | ||
const { Transform } = require('readable-stream') | ||
const abstractTransport = require('pino-abstract-transport') | ||
const sonic = require('sonic-boom') | ||
const sjs = require('secure-json-parse') | ||
const colors = require('./lib/colors') | ||
@@ -18,6 +23,5 @@ const { ERROR_LIKE_KEYS, MESSAGE_KEY, TIMESTAMP_KEY } = require('./lib/constants') | ||
const bourne = require('@hapi/bourne') | ||
const jsonParser = input => { | ||
try { | ||
return { value: bourne.parse(input, { protoAction: 'remove' }) } | ||
return { value: sjs.parse(input, { protoAction: 'remove' }) } | ||
} catch (err) { | ||
@@ -60,5 +64,3 @@ return { err } | ||
const singleLine = opts.singleLine | ||
const colorizer = colors(opts.colorize) | ||
const search = opts.search | ||
@@ -80,6 +82,2 @@ return pretty | ||
if (search && !jmespath.search(log, search)) { | ||
return | ||
} | ||
const prettifiedMessage = prettifyMessage({ log, messageKey, colorizer, messageFormat, levelLabel }) | ||
@@ -171,4 +169,34 @@ | ||
prettyFactory.prettyFactory = prettyFactory | ||
prettyFactory.default = prettyFactory | ||
module.exports = prettyFactory | ||
function build (opts = {}) { | ||
const pretty = prettyFactory(opts) | ||
return abstractTransport(function (source) { | ||
const stream = new Transform({ | ||
objectMode: true, | ||
autoDestroy: true, | ||
transform (chunk, enc, cb) { | ||
const line = pretty(chunk) | ||
cb(null, line) | ||
} | ||
}) | ||
const destination = sonic({ dest: opts.destination || 1, sync: false }) | ||
/* istanbul ignore else */ | ||
if (destination.fd === 1) { | ||
// We cannot close the output | ||
destination.end = function () { | ||
this.emit('close') | ||
} | ||
} | ||
source.on('unknown', function (line) { | ||
destination.write(line + '\n') | ||
}) | ||
pump(source, stream, destination) | ||
return stream | ||
}, { parse: 'lines' }) | ||
} | ||
module.exports = build | ||
module.exports.prettyFactory = prettyFactory | ||
module.exports.default = build |
{ | ||
"name": "pino-pretty", | ||
"version": "6.0.0", | ||
"version": "7.0.0", | ||
"description": "Prettifier for Pino log lines", | ||
@@ -35,3 +35,2 @@ "type": "commonjs", | ||
"dependencies": { | ||
"@hapi/bourne": "^2.0.0", | ||
"args": "^5.0.1", | ||
@@ -41,8 +40,9 @@ "colorette": "^1.3.0", | ||
"fast-safe-stringify": "^2.0.7", | ||
"jmespath": "^0.15.0", | ||
"joycon": "^3.0.0", | ||
"pino-abstract-transport": "^0.2.0", | ||
"pump": "^3.0.0", | ||
"readable-stream": "^3.6.0", | ||
"rfdc": "^1.3.0", | ||
"split2": "^3.1.1", | ||
"secure-json-parse": "^2.4.0", | ||
"sonic-boom": "^2.2.0", | ||
"strip-json-comments": "^3.1.1" | ||
@@ -49,0 +49,0 @@ }, |
@@ -84,6 +84,4 @@ <a id="intro"></a> | ||
system time zone. | ||
- `--search` (`-s`): Specify a search pattern according to | ||
[jmespath](http://jmespath.org/). | ||
- `--ignore` (`-i`): Ignore one or several keys, nested keys are supported with each property delimited by a dot character (`.`), | ||
keys may be escaped to target property names that contains the delimiter itself: | ||
- `--ignore` (`-i`): Ignore one or several keys, nested keys are supported with each property delimited by a dot character (`.`), | ||
keys may be escaped to target property names that contains the delimiter itself: | ||
(`-i time,hostname,req.headers,log\\.domain\\.corp/foo`) | ||
@@ -148,3 +146,2 @@ - `--hideObject` (`-H`): Hide objects from output (but not error object) | ||
translateTime: false, // --translateTime | ||
search: 'foo == `bar`', // --search | ||
ignore: 'pid,hostname', // --ignore | ||
@@ -151,0 +148,0 @@ hideObject: false, // --hideObject |
@@ -8,3 +8,4 @@ 'use strict' | ||
const dateformat = require('dateformat') | ||
const _prettyFactory = require('../') | ||
const pinoPretty = require('..') | ||
const _prettyFactory = pinoPretty.prettyFactory | ||
@@ -446,35 +447,2 @@ function prettyFactory (opts) { | ||
t.test('filter some lines based on jmespath', (t) => { | ||
t.plan(3) | ||
const pretty = prettyFactory({ search: 'foo.bar' }) | ||
const expected = [ | ||
undefined, | ||
undefined, | ||
`[${epoch}] INFO (${pid} on ${hostname}): foo\n foo: {\n "bar": true\n }\n` | ||
] | ||
const log = pino({}, new Writable({ | ||
write (chunk, enc, cb) { | ||
const formatted = pretty(chunk.toString()) | ||
t.equal( | ||
formatted, | ||
expected.shift() | ||
) | ||
cb() | ||
} | ||
})) | ||
log.info('foo') | ||
log.info({ something: 'else' }, 'foo') | ||
// only this line will be formatted | ||
log.info({ foo: { bar: true } }, 'foo') | ||
}) | ||
t.test('handles `undefined` return values', (t) => { | ||
t.plan(2) | ||
const pretty = prettyFactory({ search: 'msg == \'hello world\'' }) | ||
let formatted = pretty(`{"msg":"nope", "time":${epoch}, "level":30}`) | ||
t.equal(formatted, undefined) | ||
formatted = pretty(`{"msg":"hello world", "time":${epoch}, "level":30}`) | ||
t.equal(formatted, `[${epoch}] INFO: hello world\n`) | ||
}) | ||
t.test('formats a line with an undefined field', (t) => { | ||
@@ -733,3 +701,8 @@ t.plan(1) | ||
t.test('default options', (t) => { | ||
t.plan(1) | ||
t.doesNotThrow(pinoPretty) | ||
}) | ||
t.end() | ||
}) |
@@ -50,27 +50,2 @@ 'use strict' | ||
;['--search', '-s'].forEach((optionName) => { | ||
t.test(`does search via ${optionName}`, (t) => { | ||
t.plan(1) | ||
const child = spawn(process.argv[0], [bin, optionName, 'msg == `hello world`'], { env }) | ||
child.on('error', t.threw) | ||
child.stdout.on('data', (data) => { | ||
t.equal(data.toString(), `[${epoch}] INFO (42 on foo): hello world\n`) | ||
}) | ||
child.stdin.write(logLine) | ||
t.teardown(() => child.kill()) | ||
}) | ||
}) | ||
t.test('does search but finds only 1 out of 2', (t) => { | ||
t.plan(1) | ||
const child = spawn(process.argv[0], [bin, '-s', 'msg == `hello world`'], { env }) | ||
child.on('error', t.threw) | ||
child.stdout.on('data', (data) => { | ||
t.equal(data.toString(), `[${epoch}] INFO (42 on foo): hello world\n`) | ||
}) | ||
child.stdin.write(logLine.replace('hello world', 'hello universe')) | ||
child.stdin.write(logLine) | ||
t.teardown(() => child.kill()) | ||
}) | ||
;['--ignore', '-i'].forEach((optionName) => { | ||
@@ -118,2 +93,19 @@ t.test('does ignore multiple keys', (t) => { | ||
t.test('end stdin does not end the destination', (t) => { | ||
t.plan(2) | ||
const child = spawn(process.argv[0], [bin], { env }) | ||
child.on('error', t.threw) | ||
child.stdout.on('data', (data) => { | ||
t.equal(data.toString(), 'aaa\n') | ||
}) | ||
child.stdin.end('aaa\n') | ||
child.on('exit', function (code) { | ||
t.equal(code, 0) | ||
}) | ||
t.teardown(() => child.kill()) | ||
}) | ||
;['--timestampKey', '-a'].forEach((optionName) => { | ||
@@ -120,0 +112,0 @@ t.test(`uses specified timestamp key via ${optionName}`, (t) => { |
'use strict' | ||
const test = require('tap').test | ||
const _prettyFactory = require('../') | ||
const _prettyFactory = require('../').prettyFactory | ||
@@ -6,0 +6,0 @@ function prettyFactory (opts) { |
@@ -8,3 +8,3 @@ 'use strict' | ||
const serializers = pino.stdSerializers | ||
const _prettyFactory = require('../') | ||
const _prettyFactory = require('../').prettyFactory | ||
@@ -11,0 +11,0 @@ function prettyFactory (opts) { |
@@ -25,3 +25,2 @@ import prettyFactory from "../../"; | ||
translateTime: "UTC:h:MM:ss TT Z", | ||
search: "foo == `bar`", | ||
singleLine: false, | ||
@@ -49,3 +48,2 @@ customPrettifiers: { | ||
translateTime: "UTC:h:MM:ss TT Z", | ||
search: "foo == `bar`", | ||
singleLine: false, | ||
@@ -52,0 +50,0 @@ customPrettifiers: { |
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
296726
2927
192
+ Addedsecure-json-parse@^2.4.0
+ Addedsonic-boom@^2.2.0
+ Addedatomic-sleep@1.0.0(transitive)
+ Addedpino-abstract-transport@0.2.0(transitive)
+ Addedsecure-json-parse@2.7.0(transitive)
+ Addedsonic-boom@2.8.0(transitive)
- Removed@hapi/bourne@^2.0.0
- Removedjmespath@^0.15.0
- Removedsplit2@^3.1.1
- Removed@hapi/bourne@2.1.0(transitive)
- Removedjmespath@0.15.0(transitive)