Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pino-pretty

Package Overview
Dependencies
Maintainers
4
Versions
92
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pino-pretty - npm Package Compare versions

Comparing version 4.2.1 to 4.3.0

8

bin.js

@@ -42,2 +42,3 @@ #!/usr/bin/env node

.option('levelKey', 'Detect the log level under the specified key', CONSTANTS.LEVEL_KEY)
.option(['b', 'levelLabel'], 'Output the log level using the specified label', CONSTANTS.LEVEL_LABEL)
.option(['o', 'messageFormat'], 'Format output of message')

@@ -52,5 +53,6 @@ .option(['a', 'timestampKey'], 'Display the timestamp from the specified key', CONSTANTS.TIMESTAMP_KEY)

.example('cat log | pino-pretty', 'To prettify logs, simply pipe a log file through')
.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')
.example('cat log | pino-pretty -m fooMessage', 'To highlight a string at a key other than \'msg\'')
.example('cat log | pino-pretty --levelKey fooLevel', 'To detect the log level at a key other than \'level\'')
.example('cat log | pino-pretty --levelLabel LVL -o "{LVL}"', 'To output the log level label using a key other than \'levelLabel\'')
.example('cat log | pino-pretty -a fooTimestamp', 'To display timestamp from a key other than \'time\'')
.example('cat log | pino-pretty -t', 'To convert Epoch timestamps to ISO timestamps use the -t option')

@@ -57,0 +59,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')

@@ -47,2 +47,3 @@ 'use strict'

const levelKey = opts.levelKey
const levelLabel = opts.levelLabel
const messageFormat = opts.messageFormat

@@ -77,3 +78,3 @@ const timestampKey = opts.timestampKey

const prettifiedMessage = prettifyMessage({ log, messageKey, colorizer, messageFormat })
const prettifiedMessage = prettifyMessage({ log, messageKey, colorizer, messageFormat, levelLabel })

@@ -80,0 +81,0 @@ if (ignoreKeys) {

@@ -12,2 +12,4 @@ 'use strict'

LEVEL_LABEL: 'levelLabel',
TIMESTAMP_KEY: 'time',

@@ -19,4 +21,4 @@

50: 'ERROR',
40: 'WARN ',
30: 'INFO ',
40: 'WARN',
30: 'INFO',
20: 'DEBUG',

@@ -23,0 +25,0 @@ 10: 'TRACE'

@@ -11,4 +11,6 @@ 'use strict'

LEVEL_KEY,
LEVEL_LABEL,
TIMESTAMP_KEY,
LOGGER_KEYS
LOGGER_KEYS,
LEVELS
} = require('./constants')

@@ -182,3 +184,3 @@

if (levelKey in log === false) return undefined
return colorizer(log[levelKey])
return colorizer(log[levelKey]) + '\t'
}

@@ -203,9 +205,16 @@

*/
function prettifyMessage ({ log, messageFormat, messageKey = MESSAGE_KEY, colorizer = defaultColorizer }) {
function prettifyMessage ({ log, messageFormat, messageKey = MESSAGE_KEY, colorizer = defaultColorizer, levelLabel = LEVEL_LABEL }) {
if (messageFormat) {
const message = String(messageFormat).replace(/{([^{}]+)}/g, function (match, p1) {
if (p1 && log[p1]) {
return log[p1]
// return log level as string instead of int
if (p1 === levelLabel && log[LEVEL_KEY]) {
return LEVELS[log[LEVEL_KEY]]
}
return ''
// Parse nested key access, e.g. `{keyA.subKeyB}`.
return p1.split('.').reduce(function (prev, curr) {
if (prev && prev[curr]) {
return prev[curr]
}
return ''
}, log)
})

@@ -212,0 +221,0 @@ return colorizer.message(message)

{
"name": "pino-pretty",
"version": "4.2.1",
"version": "4.3.0",
"description": "Prettifier for Pino log lines",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -68,3 +68,5 @@ <a id="intro"></a>

Default: `level`.
- `--messageFormat` (`-o`): Format output of message, e.g. `{level} - {pid}` will output message: `INFO - 1123`
- `--levelLabel` (`-b`): Output the log level using the specified label.
Default: `levelLabel`.
- `--messageFormat` (`-o`): Format output of message, e.g. `{levelLabel} - {pid} - url:{request.url}` will output message: `INFO - 1123 - url:localhost:3000/test`
Default: `false`

@@ -71,0 +73,0 @@ - `--timestampKey` (`-a`): Define the key that contains the log timestamp.

@@ -52,3 +52,3 @@ 'use strict'

formatted,
`[${epoch}] INFO (${pid} on ${hostname}): foo\n`
`[${epoch}] INFO\t (${pid} on ${hostname}): foo\n`
)

@@ -69,3 +69,3 @@ cb()

formatted,
`[${epoch}] \u001B[32mINFO \u001B[39m (${pid} on ${hostname}): \u001B[36mfoo\u001B[39m\n`
`[${epoch}] \u001B[32mINFO\u001B[39m\t (${pid} on ${hostname}): \u001B[36mfoo\u001B[39m\n`
)

@@ -86,3 +86,3 @@ cb()

formatted,
`INFO [${epoch}] (${pid} on ${hostname}): foo\n`
`INFO\t [${epoch}] (${pid} on ${hostname}): foo\n`
)

@@ -103,3 +103,3 @@ cb()

formatted,
`[${epoch}] INFO (${pid} on ${hostname}): baz\n`
`[${epoch}] INFO\t (${pid} on ${hostname}): baz\n`
)

@@ -120,3 +120,3 @@ cb()

formatted,
`[${epoch}] WARN (${pid} on ${hostname}): foo\n`
`[${epoch}] WARN\t (${pid} on ${hostname}): foo\n`
)

@@ -137,3 +137,3 @@ cb()

formatted,
`[2018-03-30 17:35:28.992 +0000] INFO (${pid} on ${hostname}): foo\n`
`[2018-03-30 17:35:28.992 +0000] INFO\t (${pid} on ${hostname}): foo\n`
)

@@ -156,3 +156,3 @@ cb()

formatted,
`[${utcHour}:35:28 ${offset}] INFO (${pid} on ${hostname}): foo\n`
`[${utcHour}:35:28 ${offset}] INFO\t (${pid} on ${hostname}): foo\n`
)

@@ -176,3 +176,3 @@ cb()

formatted,
`[${localDate} ${localHour}:35:28.992 ${offset}] INFO (${pid} on ${hostname}): foo\n`
`[${localDate} ${localHour}:35:28.992 ${offset}] INFO\t (${pid} on ${hostname}): foo\n`
)

@@ -198,3 +198,3 @@ cb()

formatted,
`[${localDate} ${localHour}:35:28 ${offset}] INFO (${pid} on ${hostname}): foo\n`
`[${localDate} ${localHour}:35:28 ${offset}] INFO\t (${pid} on ${hostname}): foo\n`
)

@@ -221,3 +221,3 @@ cb()

const formatted = pretty(chunk.toString())
t.match(formatted, /\[.*\] INFO : hello world/)
t.match(formatted, /\[.*\] INFO\t: hello world/)
cb()

@@ -234,3 +234,3 @@ }

const msg = 'hello world'
const regex = new RegExp('\\[.*\\] INFO \\(' + name + ' on ' + hostname + '\\): ' + msg)
const regex = new RegExp('\\[.*\\] INFO\t \\(' + name + ' on ' + hostname + '\\): ' + msg)

@@ -259,3 +259,3 @@ const opts = {

const msg = 'hello world'
const regex = new RegExp('\\[.*\\] INFO \\(' + name + '/' + pid + '\\): ' + msg)
const regex = new RegExp('\\[.*\\] INFO\t \\(' + name + '/' + pid + '\\): ' + msg)

@@ -283,3 +283,3 @@ const opts = {

const msg = 'hello world'
const regex = new RegExp('\\[.*\\] INFO \\(' + process.pid + ' on ' + hostname + '\\): ' + msg)
const regex = new RegExp('\\[.*\\] INFO\t \\(' + process.pid + ' on ' + hostname + '\\): ' + msg)

@@ -309,3 +309,3 @@ const opts = {

const formatted = pretty(chunk.toString())
t.is(formatted, `INFO (${pid} on ${hostname}): hello world\n`)
t.is(formatted, `INFO\t (${pid} on ${hostname}): hello world\n`)
cb()

@@ -361,3 +361,3 @@ }

const formatted = pretty(chunk.toString())
t.is(formatted, `[${epoch}] INFO (matteo/${pid} on ${hostname}): hello world\n`)
t.is(formatted, `[${epoch}] INFO\t (matteo/${pid} on ${hostname}): hello world\n`)
cb()

@@ -429,3 +429,3 @@ }

chunk.toString(),
`[${epoch}] INFO (${pid} on ${hostname}): foo\n`
`[${epoch}] INFO\t (${pid} on ${hostname}): foo\n`
)

@@ -450,3 +450,3 @@ cb()

formatted,
`INFO [${epoch}] (${pid} on ${hostname}): foo\n`
`INFO\t [${epoch}] (${pid} on ${hostname}): foo\n`
)

@@ -471,3 +471,3 @@ cb()

undefined,
`[${epoch}] INFO (${pid} on ${hostname}): foo\n foo: {\n "bar": true\n }\n`
`[${epoch}] INFO\t (${pid} on ${hostname}): foo\n foo: {\n "bar": true\n }\n`
]

@@ -496,3 +496,3 @@ const log = pino({}, new Writable({

formatted = pretty(`{"msg":"hello world", "time":${epoch}, "level":30}`)
t.is(formatted, `[${epoch}] INFO : hello world\n`)
t.is(formatted, `[${epoch}] INFO\t: hello world\n`)
})

@@ -511,3 +511,3 @@

formatted,
`[${epoch}] INFO (${pid} on ${hostname}): foo\n`
`[${epoch}] INFO\t (${pid} on ${hostname}): foo\n`
)

@@ -583,3 +583,3 @@ cb()

const arst = pretty('{"msg":"hello world", "foo": "bar", "cow": "moo", "level":30}')
t.is(arst, 'INFO : hello world\n foo: bar_baz\n multiline\n cow: MOO\n')
t.is(arst, 'INFO\t: hello world\n foo: bar_baz\n multiline\n cow: MOO\n')
})

@@ -596,3 +596,3 @@

const arst = pretty('{"msg":"hello world", "foo": "bar", "level":30}')
t.is(arst, 'INFO : hello world\n foo: bar_baz\n')
t.is(arst, 'INFO\t: hello world\n foo: bar_baz\n')
})

@@ -606,3 +606,3 @@

chunk + '',
`[${epoch}] INFO (${pid} on ${hostname}):\n a: {\n "b": "c"\n }\n n: null\n`
`[${epoch}] INFO\t (${pid} on ${hostname}):\n a: {\n "b": "c"\n }\n n: null\n`
)

@@ -630,3 +630,3 @@ cb()

const arst = pretty(`{"msg":"hello world", "pid":"${pid}", "hostname":"${hostname}", "time":${epoch}, "level":30}`)
t.is(arst, `[${epoch}] INFO : hello world\n`)
t.is(arst, `[${epoch}] INFO\t: hello world\n`)
})

@@ -638,3 +638,3 @@

const arst = pretty(`{"msg":"hello world", "pid":"${pid}", "hostname":"${hostname}", "time":${epoch}, "level":30}`)
t.is(arst, `[${epoch}] INFO (on ${hostname}): hello world\n`)
t.is(arst, `[${epoch}] INFO\t (on ${hostname}): hello world\n`)
})

@@ -646,3 +646,3 @@

const arst = pretty(`{"msg":"hello world", "pid":"${pid}", "hostname":"${hostname}", "time":${epoch}, "level":30}`)
t.is(arst, `INFO (${pid} on ${hostname}): hello world\n`)
t.is(arst, `INFO\t (${pid} on ${hostname}): hello world\n`)
})

@@ -685,3 +685,3 @@

formatted,
`[${epoch}] INFO (${pid} on ${hostname}) </tmp/script.js>: foo\n`
`[${epoch}] INFO\t (${pid} on ${hostname}) </tmp/script.js>: foo\n`
)

@@ -698,3 +698,3 @@ cb()

const arst = pretty(`{"msg":"hello world", "@timestamp":${epoch}, "level":30}`)
t.is(arst, `[${epoch}] INFO : hello world\n`)
t.is(arst, `[${epoch}] INFO\t: hello world\n`)
})

@@ -708,3 +708,3 @@

const formatted = pretty(chunk.toString())
t.is(formatted, `INFO (${pid} on ${hostname}):\n v: 1\n`)
t.is(formatted, `INFO\t (${pid} on ${hostname}):\n v: 1\n`)
cb()

@@ -711,0 +711,0 @@ }

@@ -29,3 +29,3 @@ 'use strict'

child.stdout.on('data', (data) => {
t.is(data.toString(), '[2018-03-30 17:35:28.992 +0000] INFO (42 on foo): hello world\n')
t.is(data.toString(), '[2018-03-30 17:35:28.992 +0000] INFO\t (42 on foo): hello world\n')
})

@@ -49,3 +49,3 @@ child.stdin.write(logLine)

child.stdout.on('data', (data) => {
t.is(data.toString(), '[2018-03-30 17:35:28.992 +0000] INFO (42 on foo): hello world\n')
t.is(data.toString(), '[2018-03-30 17:35:28.992 +0000] INFO\t (42 on foo): hello world\n')
})

@@ -69,3 +69,3 @@ child.stdin.write(logLine)

child.stdout.on('data', (data) => {
t.is(data.toString(), '[2018-03-30 17:35:28.992 +0000] INFO (42 on foo): hello world\n')
t.is(data.toString(), '[2018-03-30 17:35:28.992 +0000] INFO\t (42 on foo): hello world\n')
})

@@ -89,3 +89,3 @@ child.stdin.write(logLine)

child.stdout.on('data', (data) => {
t.is(data.toString(), '[2018-03-30 17:35:28.992 +0000] INFO (42 on foo): hello world\n')
t.is(data.toString(), '[2018-03-30 17:35:28.992 +0000] INFO\t (42 on foo): hello world\n')
})

@@ -106,3 +106,3 @@ child.stdin.write(logLine)

child.stdout.on('data', (data) => {
t.is(data.toString(), '[2018-03-30 17:35:28.992 +0000] INFO (42 on foo): hello world\n')
t.is(data.toString(), '[2018-03-30 17:35:28.992 +0000] INFO\t (42 on foo): hello world\n')
})

@@ -129,3 +129,3 @@ child.stdin.write(logLine)

child.stdout.on('data', (data) => {
t.is(data.toString(), '[2018-03-30 17:35:28.992 +0000] INFO (42 on foo): hello world\n')
t.is(data.toString(), '[2018-03-30 17:35:28.992 +0000] INFO\t (42 on foo): hello world\n')
})

@@ -154,3 +154,3 @@ child.stdin.write(logLine.replace(/"msg"/, '"new_msg"'))

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')
t.is(data.toString(), '[1594416696006] FATAL\t: 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')
})

@@ -157,0 +157,0 @@ 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')

@@ -18,3 +18,3 @@ 'use strict'

child.stdout.on('data', (data) => {
t.is(data.toString(), `[${epoch}] INFO (42 on foo): hello world\n`)
t.is(data.toString(), `[${epoch}] INFO\t (42 on foo): hello world\n`)
})

@@ -31,3 +31,3 @@ child.stdin.write(logLine)

child.stdout.on('data', (data) => {
t.is(data.toString(), `INFO [${epoch}] (42 on foo): hello world\n`)
t.is(data.toString(), `INFO\t [${epoch}] (42 on foo): hello world\n`)
})

@@ -44,3 +44,3 @@ child.stdin.write(logLine)

child.stdout.on('data', (data) => {
t.is(data.toString(), '[2018-03-30 17:35:28.992 +0000] INFO (42 on foo): hello world\n')
t.is(data.toString(), '[2018-03-30 17:35:28.992 +0000] INFO\t (42 on foo): hello world\n')
})

@@ -57,3 +57,3 @@ child.stdin.write(logLine)

child.stdout.on('data', (data) => {
t.is(data.toString(), `[${epoch}] INFO (42 on foo): hello world\n`)
t.is(data.toString(), `[${epoch}] INFO\t (42 on foo): hello world\n`)
})

@@ -70,3 +70,3 @@ child.stdin.write(logLine)

child.stdout.on('data', (data) => {
t.is(data.toString(), `[${epoch}] INFO (42 on foo): hello world\n`)
t.is(data.toString(), `[${epoch}] INFO\t (42 on foo): hello world\n`)
})

@@ -84,3 +84,3 @@ child.stdin.write(logLine.replace('hello world', 'hello universe'))

child.stdout.on('data', (data) => {
t.is(data.toString(), '[1522431328992] INFO : hello world\n')
t.is(data.toString(), '[1522431328992] INFO\t: hello world\n')
})

@@ -115,3 +115,3 @@ child.stdin.write(logLine)

child.stdout.on('data', (data) => {
t.is(data.toString(), '[1522431328992] INFO : hello world\n')
t.is(data.toString(), '[1522431328992] INFO\t: hello world\n')
})

@@ -118,0 +118,0 @@ const logLine = '{"level":30,"@timestamp":1522431328992,"msg":"hello world"}\n'

@@ -50,3 +50,3 @@ 'use strict'

t.is(lines.length, expected.length + 1)
t.is(lines[0], `[${epoch}] INFO (${pid} on ${hostname}): hello world`)
t.is(lines[0], `[${epoch}] INFO\t (${pid} on ${hostname}): hello world`)
cb()

@@ -102,3 +102,3 @@ }

t.is(lines.length, expected.length + 6)
t.is(lines[0], `[${epoch}] INFO (${pid} on ${hostname}):`)
t.is(lines[0], `[${epoch}] INFO\t (${pid} on ${hostname}):`)
t.match(lines[1], /\s{4}err: {/)

@@ -134,3 +134,3 @@ t.match(lines[2], /\s{6}"type": "Error",/)

t.is(lines.length, expected.length + 6)
t.is(lines[0], `[${epoch}] INFO (${pid} on ${hostname}):`)
t.is(lines[0], `[${epoch}] INFO\t (${pid} on ${hostname}):`)
t.match(lines[1], /\s{4}err: {$/)

@@ -165,3 +165,3 @@ t.match(lines[2], /\s{6}"type": "Error",$/)

t.is(lines.length, expected.length + 7)
t.is(lines[0], `[${epoch}] INFO (${pid} on ${hostname}):`)
t.is(lines[0], `[${epoch}] INFO\t (${pid} on ${hostname}):`)
t.match(lines[1], /\s{4}err: {/)

@@ -168,0 +168,0 @@ t.match(lines[2], /\s{6}"type": "Error",/)

@@ -15,6 +15,6 @@ 'use strict'

colorized = colorizer(30)
t.is(colorized, 'INFO ')
t.is(colorized, 'INFO')
colorized = colorizer(40)
t.is(colorized, 'WARN ')
t.is(colorized, 'WARN')

@@ -31,3 +31,3 @@ colorized = colorizer(50)

colorized = colorizer('info')
t.is(colorized, 'INFO ')
t.is(colorized, 'INFO')

@@ -50,6 +50,6 @@ colorized = colorizer('use-default')

colorized = colorizer(30)
t.is(colorized, '\u001B[32mINFO \u001B[39m')
t.is(colorized, '\u001B[32mINFO\u001B[39m')
colorized = colorizer(40)
t.is(colorized, '\u001B[33mWARN \u001B[39m')
t.is(colorized, '\u001B[33mWARN\u001B[39m')

@@ -66,3 +66,3 @@ colorized = colorizer(50)

colorized = colorizer('info')
t.is(colorized, '\u001B[32mINFO \u001B[39m')
t.is(colorized, '\u001B[32mINFO\u001B[39m')

@@ -69,0 +69,0 @@ colorized = colorizer('use-default')

@@ -44,3 +44,3 @@ 'use strict'

const colorized = prettifyLevel({ log })
t.is(colorized, 'INFO ')
t.is(colorized, 'INFO\t')
})

@@ -54,3 +54,3 @@

const colorized = prettifyLevel({ log, colorizer })
t.is(colorized, '\u001B[32mINFO \u001B[39m')
t.is(colorized, '\u001B[32mINFO\u001B[39m\t')
})

@@ -106,2 +106,7 @@

t.test('returns message formatted by `messageFormat` option - levelLabel', async t => {
const str = prettifyMessage({ log: { msg: 'foo', context: 'appModule', level: 30 }, messageFormat: '[{level}] {levelLabel} {context} - {msg}' })
t.is(str, '[30] INFO appModule - foo')
})
t.test('`messageFormat` supports nested curly brackets', async t => {

@@ -112,2 +117,7 @@ const str = prettifyMessage({ log: { level: 30 }, messageFormat: '{{level}}-{level}-{{level}-{level}}' })

t.test('`messageFormat` supports nested object', async t => {
const str = prettifyMessage({ log: { level: 30, request: { url: 'localhost/test' }, msg: 'foo' }, messageFormat: '{request.url} - param: {request.params.process} - {msg}' })
t.is(str, 'localhost/test - param: - foo')
})
t.end()

@@ -114,0 +124,0 @@ })

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc