pino-pretty
Advanced tools
Comparing version 3.0.1 to 3.1.0
@@ -18,2 +18,3 @@ #!/usr/bin/env node | ||
.option(['m', 'messageKey'], 'Highlight the message under the specified key', CONSTANTS.MESSAGE_KEY) | ||
.option(['a', 'timestampKey'], 'Display the timestamp from the specified key', CONSTANTS.TIMESTAMP_KEY) | ||
.option(['t', 'translateTime'], 'Display epoch timestamps as UTC ISO format or according to an optional format string (default ISO 8601)') | ||
@@ -26,2 +27,3 @@ .option(['s', 'search'], 'Specify a search pattern according to jmespath') | ||
.example('cat log | pino-pretty -m fooMessage', 'To highlight a string at a key other than \'msg\', use') | ||
.example('cat log | pino-pretty -a fooTimestamp', 'To display timestamp from a key other than \'time\', use') | ||
.example('cat log | pino-pretty -t', 'To convert Epoch timestamps to ISO timestamps use the -t option') | ||
@@ -28,0 +30,0 @@ .example('cat log | pino-pretty -t "SYS:yyyy-mm-dd HH:MM:ss"', 'To convert Epoch timestamps to local timezone format use the -t option with "SYS:" prefixed format string') |
@@ -6,3 +6,3 @@ 'use strict' | ||
const colors = require('./lib/colors') | ||
const { ERROR_LIKE_KEYS, MESSAGE_KEY } = require('./lib/constants') | ||
const { ERROR_LIKE_KEYS, MESSAGE_KEY, TIMESTAMP_KEY } = require('./lib/constants') | ||
const { | ||
@@ -34,2 +34,3 @@ isObject, | ||
messageKey: MESSAGE_KEY, | ||
timestampKey: TIMESTAMP_KEY, | ||
translateTime: false, | ||
@@ -45,2 +46,3 @@ useMetadata: false, | ||
const messageKey = opts.messageKey | ||
const timestampKey = opts.timestampKey | ||
const errorLikeObjectKeys = opts.errorLikeObjectKeys | ||
@@ -89,3 +91,3 @@ const errorProps = opts.errorProps.split(',') | ||
const prettifiedMetadata = prettifyMetadata({ log }) | ||
const prettifiedTime = prettifyTime({ log, translateFormat: opts.translateTime }) | ||
const prettifiedTime = prettifyTime({ log, translateFormat: opts.translateTime, timestampKey }) | ||
@@ -92,0 +94,0 @@ let line = '' |
@@ -10,2 +10,4 @@ 'use strict' | ||
TIMESTAMP_KEY: 'time', | ||
LEVELS: { | ||
@@ -12,0 +14,0 @@ default: 'USERLVL', |
@@ -10,2 +10,3 @@ 'use strict' | ||
MESSAGE_KEY, | ||
TIMESTAMP_KEY, | ||
LOGGER_KEYS | ||
@@ -313,7 +314,8 @@ } = require('./constants') | ||
/** | ||
* Prettifies a timestamp if the given `log` has either `time` or `timestamp` | ||
* properties. | ||
* Prettifies a timestamp if the given `log` has either `time`, `timestamp` or custom specified timestamp | ||
* property. | ||
* | ||
* @param {object} input | ||
* @param {object} input.log The log object with the timestamp to be prettified. | ||
* @param {string} [input.timestampKey='time'] The log property that should be used to resolve timestamp value | ||
* @param {bool|string} [input.translateFormat=undefined] When `true` the | ||
@@ -328,8 +330,8 @@ * timestamp will be prettified into a string at UTC using the default | ||
*/ | ||
function prettifyTime ({ log, translateFormat = undefined }) { | ||
if ('time' in log === false && 'timestamp' in log === false) return undefined | ||
function prettifyTime ({ log, timestampKey = TIMESTAMP_KEY, translateFormat = undefined }) { | ||
if (timestampKey in log === false && 'timestamp' in log === false) return undefined | ||
if (translateFormat) { | ||
return '[' + formatTime(log.time || log.timestamp, translateFormat) + ']' | ||
return '[' + formatTime(log[timestampKey] || log.timestamp, translateFormat) + ']' | ||
} | ||
return `[${log.time || log.timestamp}]` | ||
return `[${log[timestampKey] || log.timestamp}]` | ||
} |
{ | ||
"name": "pino-pretty", | ||
"version": "3.0.1", | ||
"version": "3.1.0", | ||
"description": "Prettifier for Pino log lines", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -65,2 +65,4 @@ <a id="intro"></a> | ||
Default: `msg`. | ||
- `--timestampKey` (`-m`): Define the key that contains the log timestamp. | ||
Default: `time`. | ||
- `--translateTime` (`-t`): Translate the epoch time value into a human readable | ||
@@ -128,2 +130,3 @@ date and time string. This flag also can set the format string to apply when | ||
messageKey: 'msg', // --messageKey | ||
timestampKey: 'time', // --timestampKey | ||
translateTime: false, // --translateTime | ||
@@ -130,0 +133,0 @@ search: 'foo == `bar`', // --search |
@@ -194,2 +194,11 @@ 'use strict' | ||
t.test('returns prettified formatted time from custom field', async t => { | ||
let log = { customtime: 1554642900000 } | ||
let str = prettifyTime({ log, translateFormat: true, timestampKey: 'customtime' }) | ||
t.is(str, '[2019-04-07 13:15:00.000 +0000]') | ||
str = prettifyTime({ log, translateFormat: false, timestampKey: 'customtime' }) | ||
t.is(str, '[1554642900000]') | ||
}) | ||
t.test('returns prettified formatted time', async t => { | ||
@@ -196,0 +205,0 @@ let log = { time: 1554642900000 } |
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
246429
1704
143