pino-pretty
Advanced tools
Comparing version 9.0.1 to 9.1.0
@@ -58,2 +58,3 @@ #!/usr/bin/env node | ||
ignore: 'i', | ||
include: 'I', | ||
hideObject: 'H', | ||
@@ -60,0 +61,0 @@ singleLine: 'S' |
@@ -18,2 +18,3 @@ Usage: pino pretty [options] [command] | ||
-i, --ignore Ignore one or several keys: (`-i time,hostname`) | ||
-I, --include The opposite of `--ignore`, only include one or several keys: (`-I level,time`) | ||
-l, --levelFirst Display the log level as the first output field | ||
@@ -61,2 +62,5 @@ -L, --levelKey [value] Detect the log level under the specified key (defaults to "level") | ||
$ cat log | pino-pretty -i pid,hostname | ||
- Prettify logs but only print time and level | ||
$ cat log | pino-pretty -i time,level | ||
@@ -63,0 +67,0 @@ - Loads options from a config file |
@@ -128,2 +128,3 @@ // Type definitions for pino-pretty 7.0 | ||
* Ignore one or several keys. | ||
* Will be overridden by the option include if include is presented. | ||
* @example "time,hostname" | ||
@@ -133,2 +134,7 @@ */ | ||
/** | ||
* Include one or several keys. | ||
* @example "time,level" | ||
*/ | ||
include?: string; | ||
/** | ||
* Makes messaging synchronous. | ||
@@ -135,0 +141,0 @@ * @default false |
@@ -48,2 +48,3 @@ 'use strict' | ||
ignore: 'hostname', | ||
include: undefined, | ||
singleLine: false | ||
@@ -111,3 +112,4 @@ } | ||
const customPrettifiers = opts.customPrettifiers | ||
const ignoreKeys = opts.ignore ? new Set(opts.ignore.split(',')) : undefined | ||
const includeKeys = opts.include !== undefined ? new Set(opts.include.split(',')) : undefined | ||
const ignoreKeys = (!includeKeys && opts.ignore) ? new Set(opts.ignore.split(',')) : undefined | ||
const hideObject = opts.hideObject | ||
@@ -141,4 +143,4 @@ const singleLine = opts.singleLine | ||
if (ignoreKeys) { | ||
log = filterLog(log, ignoreKeys) | ||
if (ignoreKeys || includeKeys) { | ||
log = filterLog({ log, ignoreKeys, includeKeys }) | ||
} | ||
@@ -145,0 +147,0 @@ |
@@ -574,11 +574,29 @@ 'use strict' | ||
/** | ||
* Filter a log object by removing any ignored keys. | ||
* Filter a log object by removing or including keys accordingly. | ||
* When `includeKeys` is passed, `ignoredKeys` will be ignored. | ||
* One of ignoreKeys or includeKeys must be pass in. | ||
* | ||
* @param {object} log The log object to be modified. | ||
* @param {Set<string> | Array<string>} ignoreKeys An array of strings identifying the properties to be removed. | ||
* @param {object} input | ||
* @param {object} input.log The log object to be modified. | ||
* @param {Set<string> | Array<string> | undefined} input.ignoreKeys | ||
* An array of strings identifying the properties to be removed. | ||
* @param {Set<string> | Array<string> | undefined} input.includeKeys | ||
* An array of strings identifying the properties to be included. | ||
* | ||
* @returns {object} A new `log` object instance that does not include the ignored keys. | ||
* @returns {object} A new `log` object instance that | ||
* either only includes the keys in ignoreKeys | ||
* or does not include those in ignoredKeys. | ||
*/ | ||
function filterLog (log, ignoreKeys) { | ||
function filterLog ({ log, ignoreKeys, includeKeys }) { | ||
const logCopy = fastCopy(log) | ||
if (includeKeys) { | ||
const logIncluded = {} | ||
includeKeys.forEach((key) => { | ||
logIncluded[key] = logCopy[key] | ||
}) | ||
return logIncluded | ||
} | ||
ignoreKeys.forEach((ignoreKey) => { | ||
@@ -585,0 +603,0 @@ deleteLogProperty(logCopy, ignoreKey) |
{ | ||
"name": "pino-pretty", | ||
"version": "9.0.1", | ||
"version": "9.1.0", | ||
"description": "Prettifier for Pino log lines", | ||
@@ -5,0 +5,0 @@ "type": "commonjs", |
@@ -32,4 +32,3 @@ <a id="intro"></a> | ||
Using the [example script][exscript] from the Pino module, and specifying | ||
that logs should be colored and the time translated, we can see what the | ||
Using the [example script][exscript] from the Pino module, we can see what the | ||
prettified logs will look like: | ||
@@ -39,3 +38,3 @@ | ||
[exscript]: https://github.com/pinojs/pino/blob/fc4c83b/example.js | ||
[exscript]: https://github.com/pinojs/pino/blob/25ba61f40ea5a1a753c85002812426d765da52a4/examples/basic.js | ||
@@ -96,4 +95,6 @@ <a id="install"></a> | ||
keys may be escaped to target property names that contains the delimiter itself: | ||
(`-i time,hostname,req.headers,log\\.domain\\.corp/foo`) | ||
(`-i time,hostname,req.headers,log\\.domain\\.corp/foo`). | ||
The `--ignore` option would be ignored, if both `--ignore` and `--include` are passed. | ||
Default: `hostname`. | ||
- `--include` (`-I`): The opposite of `--ignore`. Include one or several keys. | ||
- `--hideObject` (`-H`): Hide objects from output (but not error object) | ||
@@ -250,2 +251,3 @@ - `--singleLine` (`-S`): Print each log message on a single line (errors will still be multi-line) | ||
ignore: 'pid,hostname', // --ignore | ||
include: 'level,time', // --include | ||
hideObject: false, // --hideObject | ||
@@ -252,0 +254,0 @@ singleLine: false, // --singleLine |
@@ -778,2 +778,30 @@ 'use strict' | ||
t.test('include nothing', (t) => { | ||
t.plan(1) | ||
const pretty = prettyFactory({ include: '' }) | ||
const arst = pretty(`{"msg":"hello world", "pid":"${pid}", "hostname":"${hostname}", "time":${epoch}, "level":30}`) | ||
t.equal(arst, 'hello world\n') | ||
}) | ||
t.test('include multiple keys', (t) => { | ||
t.plan(1) | ||
const pretty = prettyFactory({ include: 'time,level' }) | ||
const arst = pretty(`{"msg":"hello world", "pid":"${pid}", "hostname":"${hostname}", "time":${epoch}, "level":30}`) | ||
t.equal(arst, `[${formattedEpoch}] INFO: hello world\n`) | ||
}) | ||
t.test('include a single key', (t) => { | ||
t.plan(1) | ||
const pretty = prettyFactory({ include: 'level' }) | ||
const arst = pretty(`{"msg":"hello world", "pid":"${pid}", "hostname":"${hostname}", "time":${epoch}, "level":30}`) | ||
t.equal(arst, 'INFO: hello world\n') | ||
}) | ||
t.test('include should override ignore', (t) => { | ||
t.plan(1) | ||
const pretty = prettyFactory({ ignore: 'time,level', include: 'time,level' }) | ||
const arst = pretty(`{"msg":"hello world", "pid":"${pid}", "hostname":"${hostname}", "time":${epoch}, "level":30}`) | ||
t.equal(arst, `[${formattedEpoch}] INFO: hello world\n`) | ||
}) | ||
t.test('prettifies trace caller', (t) => { | ||
@@ -780,0 +808,0 @@ t.plan(1) |
@@ -390,15 +390,22 @@ 'use strict' | ||
tap.test('#filterLog', t => { | ||
const { filterLog } = utils | ||
const logData = { | ||
level: 30, | ||
time: 1522431328992, | ||
data1: { | ||
data2: { 'data-3': 'bar' }, | ||
error: new Error('test') | ||
} | ||
const logData = { | ||
level: 30, | ||
time: 1522431328992, | ||
data1: { | ||
data2: { 'data-3': 'bar' }, | ||
error: new Error('test') | ||
} | ||
} | ||
const logData2 = Object.assign({ | ||
'logging.domain.corp/operation': { | ||
id: 'foo', | ||
producer: 'bar' | ||
} | ||
}, logData) | ||
tap.test('#filterLog with an ignoreKeys option', t => { | ||
const { filterLog } = utils | ||
t.test('filterLog removes single entry', async t => { | ||
const result = filterLog(logData, ['data1.data2.data-3']) | ||
const result = filterLog({ log: logData, ignoreKeys: ['data1.data2.data-3'] }) | ||
t.same(result, { level: 30, time: 1522431328992, data1: { data2: { }, error: new Error('test') } }) | ||
@@ -408,3 +415,3 @@ }) | ||
t.test('filterLog removes multiple entries', async t => { | ||
const result = filterLog(logData, ['time', 'data1']) | ||
const result = filterLog({ log: logData, ignoreKeys: ['time', 'data1'] }) | ||
t.same(result, { level: 30 }) | ||
@@ -414,15 +421,8 @@ }) | ||
t.test('filterLog keeps error instance', async t => { | ||
const result = filterLog(logData, []) | ||
const result = filterLog({ log: logData, ignoreKeys: [] }) | ||
t.equal(logData.data1.error, result.data1.error) | ||
}) | ||
const logData2 = Object.assign({ | ||
'logging.domain.corp/operation': { | ||
id: 'foo', | ||
producer: 'bar' | ||
} | ||
}, logData) | ||
t.test('filterLog removes entry with escape sequence', async t => { | ||
const result = filterLog(logData2, ['data1', 'logging\\.domain\\.corp/operation']) | ||
const result = filterLog({ log: logData2, ignoreKeys: ['data1', 'logging\\.domain\\.corp/operation'] }) | ||
t.same(result, { level: 30, time: 1522431328992 }) | ||
@@ -432,3 +432,3 @@ }) | ||
t.test('filterLog removes entry with escape sequence nested', async t => { | ||
const result = filterLog(logData2, ['data1', 'logging\\.domain\\.corp/operation.producer']) | ||
const result = filterLog({ log: logData2, ignoreKeys: ['data1', 'logging\\.domain\\.corp/operation.producer'] }) | ||
t.same(result, { level: 30, time: 1522431328992, 'logging.domain.corp/operation': { id: 'foo' } }) | ||
@@ -440,2 +440,36 @@ }) | ||
const ignoreKeysArray = [ | ||
undefined, | ||
['level'], | ||
['level', 'data1.data2.data-3'] | ||
] | ||
ignoreKeysArray.forEach(ignoreKeys => { | ||
tap.test(`#filterLog with an includeKeys option when the ignoreKeys being ${ignoreKeys}`, t => { | ||
const { filterLog } = utils | ||
t.test('filterLog include nothing', async t => { | ||
const result = filterLog({ log: logData, ignoreKeys, includeKeys: [] }) | ||
t.same(result, {}) | ||
}) | ||
t.test('filterLog include single entry', async t => { | ||
const result = filterLog({ log: logData, ignoreKeys, includeKeys: ['time'] }) | ||
t.same(result, { time: 1522431328992 }) | ||
}) | ||
t.test('filterLog include multiple entries', async t => { | ||
const result = filterLog({ log: logData, ignoreKeys, includeKeys: ['time', 'data1'] }) | ||
t.same(result, { | ||
time: 1522431328992, | ||
data1: { | ||
data2: { 'data-3': 'bar' }, | ||
error: new Error('test') | ||
} | ||
}) | ||
}) | ||
t.end() | ||
}) | ||
}) | ||
tap.test('#filterLog with circular references', t => { | ||
@@ -451,3 +485,3 @@ const { filterLog } = utils | ||
t.test('filterLog removes single entry', async t => { | ||
const result = filterLog(logData, ['data1']) | ||
const result = filterLog({ log: logData, ignoreKeys: ['data1'] }) | ||
@@ -461,2 +495,18 @@ t.same(result.circular.level, result.level) | ||
t.test('filterLog includes single entry', async t => { | ||
const result = filterLog({ log: logData, includeKeys: ['data1'] }) | ||
t.same(result, { data1: 'test' }) | ||
}) | ||
t.test('filterLog includes circular keys', async t => { | ||
const result = filterLog({ log: logData, includeKeys: ['level', 'circular'] }) | ||
t.same(result.circular.level, logData.level) | ||
t.same(result.circular.time, logData.time) | ||
delete result.circular | ||
t.same(result, { level: 30 }) | ||
}) | ||
t.end() | ||
@@ -463,0 +513,0 @@ }) |
Sorry, the diff of this file is not supported yet
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
3930
363
178991