pino-pretty
Advanced tools
Comparing version 3.5.0 to 3.6.0
@@ -41,2 +41,3 @@ #!/usr/bin/env node | ||
.option(['m', 'messageKey'], 'Highlight the message under the specified key', CONSTANTS.MESSAGE_KEY) | ||
.option('levelKey', 'Detect the log level under the specified key', CONSTANTS.LEVEL_KEY) | ||
.option(['o', 'messageFormat'], 'Format output of message') | ||
@@ -52,2 +53,3 @@ .option(['a', 'timestampKey'], 'Display the timestamp from the specified key', CONSTANTS.TIMESTAMP_KEY) | ||
.example('cat log | pino-pretty -m fooMessage', 'To highlight a string at a key other than \'msg\', use') | ||
.example('cat log | pino-pretty --levelKey fooLevel', 'To detect the log level at a key other than \'level\', use') | ||
.example('cat log | pino-pretty -a fooTimestamp', 'To display timestamp from a key other than \'time\', use') | ||
@@ -67,2 +69,3 @@ .example('cat log | pino-pretty -t', 'To convert Epoch timestamps to ISO timestamps use the -t option') | ||
messageKey: DEFAULT_VALUE, | ||
levelKey: DEFAULT_VALUE, | ||
timestampKey: DEFAULT_VALUE | ||
@@ -72,2 +75,3 @@ } | ||
}) | ||
// Remove default values | ||
@@ -74,0 +78,0 @@ opts = filter(opts, value => value !== DEFAULT_VALUE) |
@@ -46,2 +46,3 @@ 'use strict' | ||
const messageKey = opts.messageKey | ||
const levelKey = opts.levelKey | ||
const messageFormat = opts.messageFormat | ||
@@ -92,3 +93,3 @@ const timestampKey = opts.timestampKey | ||
const prettifiedLevel = prettifyLevel({ log, colorizer }) | ||
const prettifiedLevel = prettifyLevel({ log, colorizer, levelKey }) | ||
const prettifiedMetadata = prettifyMetadata({ log }) | ||
@@ -142,3 +143,3 @@ const prettifiedTime = prettifyTime({ log, translateFormat: opts.translateTime, timestampKey }) | ||
} else { | ||
const skipKeys = typeof log[messageKey] === 'string' ? [messageKey] : undefined | ||
const skipKeys = [messageKey, levelKey].filter(key => typeof log[key] === 'string') | ||
const prettifiedObject = prettifyObject({ | ||
@@ -145,0 +146,0 @@ input: log, |
@@ -10,2 +10,4 @@ 'use strict' | ||
LEVEL_KEY: 'level', | ||
TIMESTAMP_KEY: 'time', | ||
@@ -12,0 +14,0 @@ |
@@ -10,2 +10,3 @@ 'use strict' | ||
MESSAGE_KEY, | ||
LEVEL_KEY, | ||
TIMESTAMP_KEY, | ||
@@ -170,5 +171,6 @@ LOGGER_KEYS | ||
* @param {object} input | ||
* @param {object} input.log The log object which should have a `level` property. | ||
* @param {object} input.log The log object. | ||
* @param {function} [input.colorizer] A colorizer function that accepts a level | ||
* value and returns a colorized string. Default: a no-op colorizer. | ||
* @param {string} [levelKey='level'] The key to find the level under. | ||
* | ||
@@ -179,5 +181,5 @@ * @returns {undefined|string} If `log` does not have a `level` property then | ||
*/ | ||
function prettifyLevel ({ log, colorizer = defaultColorizer }) { | ||
if ('level' in log === false) return undefined | ||
return colorizer(log.level) | ||
function prettifyLevel ({ log, colorizer = defaultColorizer, levelKey = LEVEL_KEY }) { | ||
if (levelKey in log === false) return undefined | ||
return colorizer(log[levelKey]) | ||
} | ||
@@ -184,0 +186,0 @@ |
{ | ||
"name": "pino-pretty", | ||
"version": "3.5.0", | ||
"version": "3.6.0", | ||
"description": "Prettifier for Pino log lines", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
<a id="intro"></a> | ||
# pino-pretty | ||
[![Build Status](https://travis-ci.org/pinojs/pino-pretty.svg?branch=master)](https://travis-ci.org/pinojs/pino-pretty) | ||
[![Coverage Status](https://coveralls.io/repos/github/pinojs/pino-pretty/badge.svg?branch=master)](https://coveralls.io/github/pinojs/pino-pretty?branch=master) | ||
[![NPM Package Version](https://badgen.net/npm/v/pino-pretty)](https://www.npmjs.com/package/pino-pretty) | ||
[![Build Status](https://badgen.net/travis/pinojs/pino-pretty/master)](https://travis-ci.org/pinojs/pino-pretty) | ||
[![Coverage Status](https://badgen.net/coveralls/c/github/pinojs/pino-pretty/master)](https://coveralls.io/github/pinojs/pino-pretty?branch=master) | ||
@@ -65,2 +66,4 @@ This module provides a basic [ndjson](http://ndjson.org/) formatter. If an | ||
Default: `msg`. | ||
- `--levelKey` (`--levelKey`): Define the key that contains the level of the log. | ||
Default: `level`. | ||
- `--messageFormat` (`-o`): Format output of message, e.g. `{level} - {pid}` will output message: `INFO - 1123` | ||
@@ -133,2 +136,3 @@ Default: `false` | ||
messageKey: 'msg', // --messageKey | ||
levelKey: 'level', // --levelKey | ||
messageFormat: false // --messageFormat | ||
@@ -135,0 +139,0 @@ timestampKey: 'time', // --timestampKey |
@@ -108,2 +108,18 @@ 'use strict' | ||
t.test('can use different level keys', (t) => { | ||
t.plan(1) | ||
const pretty = prettyFactory({ levelKey: 'bar' }) | ||
const log = pino({}, new Writable({ | ||
write (chunk, enc, cb) { | ||
const formatted = pretty(chunk.toString()) | ||
t.is( | ||
formatted, | ||
`[${epoch}] WARN (${pid} on ${hostname}): foo\n` | ||
) | ||
cb() | ||
} | ||
})) | ||
log.info({ msg: 'foo', bar: 'warn' }) | ||
}) | ||
t.test('will format time to UTC', (t) => { | ||
@@ -110,0 +126,0 @@ t.plan(1) |
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
261828
2089
169