Socket
Socket
Sign inDemoInstall

pino-pretty

Package Overview
Dependencies
Maintainers
4
Versions
88
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 8.1.0 to 9.0.0

3

index.js

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

timestampKey: TIMESTAMP_KEY,
translateTime: false,
translateTime: true,
useMetadata: false,

@@ -48,2 +48,3 @@ outputStream: process.stdout,

hideObject: false,
ignore: 'hostname',
singleLine: false

@@ -50,0 +51,0 @@ }

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

DATE_FORMAT: 'yyyy-mm-dd HH:MM:ss.l o',
DATE_FORMAT_SIMPLE: 'HH:MM:ss.l',

@@ -7,0 +8,0 @@ ERROR_LIKE_KEYS: ['err', 'error'],

@@ -17,3 +17,4 @@ 'use strict'

LOGGER_KEYS,
LEVELS
LEVELS,
DATE_FORMAT_SIMPLE
} = require('./constants')

@@ -78,3 +79,3 @@

if (translateTime === true) {
return dateformat(instant, 'UTC:' + DATE_FORMAT)
return dateformat(instant, DATE_FORMAT_SIMPLE)
}

@@ -81,0 +82,0 @@

{
"name": "pino-pretty",
"version": "8.1.0",
"version": "9.0.0",
"description": "Prettifier for Pino log lines",

@@ -42,3 +42,3 @@ "type": "commonjs",

"minimist": "^1.2.6",
"on-exit-leak-free": "^1.0.0",
"on-exit-leak-free": "^2.1.0",
"pino-abstract-transport": "^1.0.0",

@@ -59,3 +59,3 @@ "pump": "^3.0.0",

"tap": "^16.0.0",
"tsd": "^0.21.0",
"tsd": "^0.22.0",
"typescript": "^4.4.3"

@@ -62,0 +62,0 @@ },

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

This module provides a basic [ndjson](http://ndjson.org/) formatter. If an
This module provides a basic [ndjson](http://ndjson.org/) formatter to be used in __development__. If an
incoming line looks like it could be a log line from an ndjson logger, in

@@ -24,3 +24,3 @@ particular the [Pino](https://getpino.io/) logging library, then it will apply

```
[1522431328992] INFO (42 on foo): hello world
[17:35:28.992] INFO (42): hello world
```

@@ -89,3 +89,4 @@

letters, see the [`dateformat` documentation](https://www.npmjs.com/package/dateformat).
- The default format is `yyyy-mm-dd HH:MM:ss.l o` in UTC.
- The default format is `HH:MM:ss.l` in the local timezone.
- Require a `UTC:` prefix to translate time to UTC, e.g. `UTC:yyyy-mm-dd HH:MM:ss.l o`.
- Require a `SYS:` prefix to translate time to the local system's time zone. A

@@ -97,2 +98,3 @@ shortcut `SYS:standard` to translate time to `yyyy-mm-dd HH:MM:ss.l o` in

(`-i time,hostname,req.headers,log\\.domain\\.corp/foo`)
Default: `hostname`.
- `--hideObject` (`-H`): Hide objects from output (but not error object)

@@ -99,0 +101,0 @@ - `--singleLine` (`-S`): Print each log message on a single line (errors will still be multi-line)

'use strict'
process.env.TZ = 'UTC'
const { Writable } = require('readable-stream')

@@ -30,3 +32,3 @@ const os = require('os')

const epoch = 1522431328992
const formattedEpoch = '2018-03-30 17:35:28.992 +0000'
const formattedEpoch = '17:35:28.992'
const pid = process.pid

@@ -60,3 +62,3 @@ const hostname = os.hostname()

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

@@ -77,3 +79,3 @@ cb()

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

@@ -92,3 +94,3 @@ cb()

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

@@ -115,3 +117,3 @@ cb()

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

@@ -132,3 +134,3 @@ cb()

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

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

formatted,
`[${epoch}] LEVEL: ok (${pid} on ${hostname}): foo\n`
`[${formattedEpoch}] LEVEL: ok (${pid}): foo\n`
)

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

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

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

formatted,
`[${epoch}] INFO (NAME: logger/${pid} on ${hostname}): foo\n`
`[${formattedEpoch}] INFO (NAME: logger/${pid}): foo\n`
)

@@ -212,3 +214,3 @@ cb()

}
const pretty = prettyFactory({ customPrettifiers })
const pretty = prettyFactory({ customPrettifiers, ignore: '' })
const log = pino({}, new Writable({

@@ -219,3 +221,3 @@ write (chunk, enc, cb) {

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

@@ -239,3 +241,3 @@ cb()

formatted,
`TIME: ${epoch} INFO (${pid} on ${hostname}): foo\n`
`TIME: ${formattedEpoch} INFO (${pid}): foo\n`
)

@@ -259,3 +261,3 @@ cb()

formatted,
`[${epoch}] INFO (${pid} on ${hostname}) <CALLER: test.js:10>: foo\n`
`[${formattedEpoch}] INFO (${pid}) <CALLER: test.js:10>: foo\n`
)

@@ -279,3 +281,3 @@ cb()

formatted,
`TIME: ${formattedEpoch} INFO (${pid} on ${hostname}): foo\n`
`TIME: ${formattedEpoch} INFO (${pid}): foo\n`
)

@@ -296,3 +298,3 @@ cb()

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

@@ -315,3 +317,3 @@ cb()

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

@@ -336,3 +338,3 @@ cb()

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

@@ -359,3 +361,3 @@ cb()

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

@@ -394,3 +396,3 @@ cb()

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

@@ -442,3 +444,3 @@ const opts = {

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

@@ -468,3 +470,3 @@ const opts = {

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

@@ -520,3 +522,3 @@ }

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

@@ -588,3 +590,3 @@ }

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

@@ -612,4 +614,4 @@ const log = pino({}, new Writable({

undefined,
`[${epoch}] DEBUG (${pid} on ${hostname}): bar\n`,
`[${epoch}] INFO (${pid} on ${hostname}): baz\n`
`[${formattedEpoch}] DEBUG (${pid}): bar\n`,
`[${formattedEpoch}] INFO (${pid}): baz\n`
]

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

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

@@ -746,3 +748,3 @@ cb()

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

@@ -771,3 +773,3 @@ cb()

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

@@ -779,3 +781,3 @@

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

@@ -825,3 +827,3 @@

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

@@ -838,3 +840,3 @@ cb()

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

@@ -861,3 +863,3 @@

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

@@ -882,3 +884,3 @@ }

const formatted = pretty(chunk.toString())
t.equal(formatted, `[${epoch}] INFO (${pid} on ${hostname}): message {"extra":{"foo":"bar","number":42},"upper":"FOOBAR"}\n`)
t.equal(formatted, `[${formattedEpoch}] INFO (${pid}): message {"extra":{"foo":"bar","number":42},"upper":"FOOBAR"}\n`)

@@ -897,3 +899,3 @@ cb()

const formatted = pretty(chunk.toString())
t.equal(formatted, `[${epoch}] INFO (${pid} on ${hostname}): message\n`)
t.equal(formatted, `[${formattedEpoch}] INFO (${pid}): message\n`)
cb()

@@ -961,3 +963,3 @@ }

t.equal(formatted, `[${epoch}] INFO (${pid} on ${hostname}): message {"extra":{"foo":"bar","number":42},"upper":"FOOBAR"}\n`)
t.equal(formatted, `[${formattedEpoch}] INFO (${pid}): message {"extra":{"foo":"bar","number":42},"upper":"FOOBAR"}\n`)
})

@@ -985,3 +987,3 @@

t.equal(formatted, `[${epoch}] INFO (${pid} on ${hostname}): message {"extra":{"foo":"bar","number":42},"upper":"foobar"}\n`)
t.equal(formatted, `[${formattedEpoch}] INFO (${pid}): message {"extra":{"foo":"bar","number":42},"upper":"foobar"}\n`)
})

@@ -988,0 +990,0 @@

'use strict'
process.env.TZ = 'UTC'
const path = require('path')

@@ -24,3 +26,3 @@ const spawn = require('child_process').spawn

fs.writeFileSync(configFile, 'module.exports = { translateTime: true }')
const env = { TERM: 'dumb' }
const env = { TERM: 'dumb', TZ: 'UTC' }
const child = spawn(process.argv[0], [bin], { env, cwd: tmpDir })

@@ -30,3 +32,3 @@ // Validate that the time has been translated

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

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

fs.writeFileSync(packageJsonFile, JSON.stringify({ type: 'module' }, null, 4))
const env = { TERM: 'dumb' }
const env = { TERM: ' dumb', TZ: 'UTC' }
const child = spawn(process.argv[0], [bin], { env, cwd: tmpDir })

@@ -54,3 +56,3 @@ // Validate that the time has been translated

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

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

fs.writeFileSync(configFile, JSON.stringify({ translateTime: true }, null, 4))
const env = { TERM: 'dumb' }
const env = { TERM: ' dumb', TZ: 'UTC' }
const child = spawn(process.argv[0], [bin], { env, cwd: tmpDir })

@@ -76,3 +78,3 @@ // Validate that the time has been translated

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

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

fs.writeFileSync(configFile, JSON.stringify({ translateTime: true }, null, 4))
const env = { TERM: 'dumb' }
const env = { TERM: ' dumb', TZ: 'UTC' }
const child = spawn(process.argv[0], [bin], { env, cwd: tmpDir })

@@ -97,3 +99,3 @@ // Validate that the time has been translated

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

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

fs.writeFileSync(configFile, JSON.stringify({ translateTime: true }, null, 4))
const env = { TERM: 'dumb' }
const env = { TERM: ' dumb', TZ: 'UTC' }
const child = spawn(process.argv[0], [bin, '--config', configFile], { env, cwd: tmpDir })

@@ -118,3 +120,3 @@ // Validate that the time has been translated

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

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

fs.writeFileSync(configFile, 'module.exports = { translateTime: true }')
const env = { TERM: 'dumb' }
const env = { TERM: ' dumb', TZ: 'UTC' }
const child = spawn(process.argv[0], [bin, '--config', configFile], { env, cwd: tmpDir })

@@ -136,3 +138,3 @@ // Validate that the time has been translated

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

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

// Set messageKey: 'new_msg' using command line option
const env = { TERM: 'dumb' }
const env = { TERM: ' dumb', TZ: 'UTC' }
const child = spawn(process.argv[0], [bin, optionName, 'new_msg'], { env, cwd: tmpDir })

@@ -161,3 +163,3 @@ // Validate that the time has been translated and correct message key has been used

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

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

// Set messageKey: 'new_msg' using command line option
const env = { TERM: 'dumb' }
const env = { TERM: ' dumb', TZ: 'UTC' }
const child = spawn(process.argv[0], [bin], { env, cwd: tmpDir })

@@ -188,3 +190,3 @@ // Validate that the time has been translated and correct message key has been used

child.stdout.on('data', (data) => {
t.equal(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\n querySql: SELECTT * FROM "test" WHERE id = $1;\n queryArgs: 12\n')
t.equal(data.toString(), '[21:31:36.006] 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\n querySql: SELECTT * FROM "test" WHERE id = $1;\n queryArgs: 12\n')
})

@@ -201,3 +203,3 @@ 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')

const args = [bin, '--config', 'pino-pretty.config.missing.json']
const env = { TERM: 'dumb' }
const env = { TERM: ' dumb', TZ: 'UTC' }
const child = spawn(process.argv[0], args, { env, cwd: tmpDir })

@@ -212,6 +214,4 @@ child.on('close', (code) => t.equal(code, 1))

child.on('close', function () {
t.equal(
data.toString().indexOf('Error: Failed to load runtime configuration file: pino-pretty.config.missing.json') >= 0,
true
)
t.match(
data.toString(), 'Error: Failed to load runtime configuration file: pino-pretty.config.missing.json')
})

@@ -225,3 +225,3 @@ t.teardown(() => child.kill())

fs.writeFileSync(configFile, 'module.exports = () => {}')
const env = { TERM: 'dumb' }
const env = { TERM: ' dumb', TZ: 'UTC' }
const child = spawn(process.argv[0], [bin], { env, cwd: tmpDir })

@@ -236,3 +236,3 @@ child.on('close', (code) => t.equal(code, 1))

child.on('close', function () {
t.equal(data.indexOf('Error: Invalid runtime configuration file: pino-pretty.config.js') >= 0, true)
t.match(data, 'Error: Invalid runtime configuration file: pino-pretty.config.js')
})

@@ -247,3 +247,3 @@ t.teardown(() => child.kill())

const args = [bin, '--config', path.relative(tmpDir, configFile)]
const env = { TERM: 'dumb' }
const env = { TERM: ' dumb', TZ: 'UTC' }
const child = spawn(process.argv[0], args, { env, cwd: tmpDir })

@@ -258,3 +258,3 @@ child.on('close', (code) => t.equal(code, 1))

child.on('close', function () {
t.equal(data.indexOf('Error: Invalid runtime configuration file: pino-pretty.config.invalid.js') >= 0, true)
t.match(data, 'Error: Invalid runtime configuration file: pino-pretty.config.invalid.js')
})

@@ -266,3 +266,3 @@ t.teardown(() => child.kill())

t.plan(1)
const env = { TERM: 'dumb' }
const env = { TERM: ' dumb', TZ: 'UTC' }
const child = spawn(process.argv[0], [bin, '--help'], { env })

@@ -269,0 +269,0 @@ const file = fs.readFileSync('help/help.txt').toString()

'use strict'
process.env.TZ = 'UTC'
const path = require('path')

@@ -10,3 +12,4 @@ const spawn = require('child_process').spawn

const logLine = '{"level":30,"time":1522431328992,"msg":"hello world","pid":42,"hostname":"foo"}\n'
const env = { TERM: 'dumb' }
const env = { TERM: 'dumb', TZ: 'UTC' }
const formattedEpoch = '17:35:28.992'

@@ -19,3 +22,3 @@ test('cli', (t) => {

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

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

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

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

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

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

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

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

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

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

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

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

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

@@ -113,3 +116,3 @@ child.stdin.write('{"level":1,"time":1522431328992,"msg":"hello world","pid":42,"hostname":"foo"}\n')

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

@@ -126,3 +129,3 @@ child.stdin.write('{"level":1,"time":1522431328992,"msg":"hello world","pid":42,"hostname":"foo"}\n')

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

@@ -141,3 +144,3 @@ child.stdin.write('{"level":1,"time":1522431328992,"msg":"hello world","pid":42,"hostname":"foo"}\n')

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@@ -289,3 +292,3 @@ const logLine = '{"level":30,"time":1522431328992,"msg":"hello world","log.domain.corp/foo":"bar"}\n'

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

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

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

@@ -335,3 +338,3 @@ child.stdin.write(logLineWithExtra)

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

@@ -342,3 +345,14 @@ child.stdin.write(logLineNested)

t.test('change TZ', (t) => {
t.plan(1)
const child = spawn(process.argv[0], [bin], { env: { ...env, TZ: 'Europe/Amsterdam' } })
child.on('error', t.threw)
child.stdout.on('data', (data) => {
t.equal(data.toString(), '[19:35:28.992] INFO (42): hello world\n')
})
child.stdin.write(logLine)
t.teardown(() => child.kill())
})
t.end()
})
'use strict'
process.env.TZ = 'UTC'
const test = require('tap').test

@@ -4,0 +6,0 @@ const _prettyFactory = require('../').prettyFactory

'use strict'
process.env.TZ = 'UTC'
const Writable = require('stream').Writable
const os = require('os')
const test = require('tap').test

@@ -21,6 +22,6 @@ const pino = require('pino')

const epoch = 1522431328992
const formattedEpoch = '17:35:28.992'
const pid = process.pid
const hostname = os.hostname()
test('error like objects tests', { only: true }, (t) => {
test('error like objects tests', (t) => {
t.beforeEach(() => {

@@ -47,3 +48,3 @@ Date.originalNow = Date.now

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

@@ -99,3 +100,3 @@ }

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

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

t.equal(lines.length, expected.length + 5)
t.equal(lines[0], `[${epoch}] INFO (${pid} on ${hostname}): hello world {"extra":{"a":1,"b":2}}`)
t.equal(lines[0], `[${formattedEpoch}] INFO (${pid}): hello world {"extra":{"a":1,"b":2}}`)
t.match(lines[1], /\s{4}err: {/)

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

t.equal(lines.length, 3)
t.equal(lines[0], `[${epoch}] INFO (${pid} on ${hostname}): hello world`)
t.equal(lines[0], `[${formattedEpoch}] INFO (${pid}): hello world`)
t.equal(lines[1], ' err: error is hello world')

@@ -198,3 +199,3 @@ t.equal(lines[2], '')

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

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

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

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

t.equal(lines.length, expected.length + 1)
t.equal(lines[0], `[${epoch}] INFO (${pid} on ${hostname}): ${expected[0]}`)
t.equal(lines[0], `[${formattedEpoch}] INFO (${pid}): ${expected[0]}`)
t.equal(lines[1], ` ${expected[1]}`)

@@ -306,0 +307,0 @@ t.equal(lines[2], ` ${expected[2]}`)

'use strict'
process.env.TZ = 'UTC'
const tap = require('tap')

@@ -36,3 +38,3 @@ const fastCopy = require('fast-copy')

const formattedTime = internals.formatTime(epochMS, true)
t.equal(formattedTime, '2019-04-06 17:30:00.000 +0000')
t.equal(formattedTime, '17:30:00.000')
})

@@ -62,3 +64,3 @@

const formattedTime = internals.formatTime(dateStr, true)
t.equal(formattedTime, '2019-04-06 17:30:00.000 +0000')
t.equal(formattedTime, '17:30:00.000')
})

@@ -65,0 +67,0 @@

'use strict'
process.env.TZ = 'UTC'
const tap = require('tap')

@@ -297,3 +299,3 @@ const getColorizer = require('../../lib/colors')

let str = prettifyTime({ log, translateFormat: true, timestampKey: 'customtime' })
t.equal(str, '[2019-04-07 13:15:00.000 +0000]')
t.equal(str, '[13:15:00.000]')

@@ -307,15 +309,15 @@ str = prettifyTime({ log, translateFormat: false, timestampKey: 'customtime' })

let str = prettifyTime({ log, translateFormat: true })
t.equal(str, '[2019-04-07 13:15:00.000 +0000]')
t.equal(str, '[13:15:00.000]')
log = { timestamp: 1554642900000 }
str = prettifyTime({ log, translateFormat: true })
t.equal(str, '[2019-04-07 13:15:00.000 +0000]')
t.equal(str, '[13:15:00.000]')
log = { time: '2019-04-07T09:15:00.000-04:00' }
str = prettifyTime({ log, translateFormat: true })
t.equal(str, '[2019-04-07 13:15:00.000 +0000]')
t.equal(str, '[13:15:00.000]')
log = { timestamp: '2019-04-07T09:15:00.000-04:00' }
str = prettifyTime({ log, translateFormat: true })
t.equal(str, '[2019-04-07 13:15:00.000 +0000]')
t.equal(str, '[13:15:00.000]')

@@ -382,4 +384,4 @@ log = { time: 1554642900000 }

})
t.same(asString, '[2018-03-30 17:35:28.992 +0000]')
t.same(asNumber, '[2018-03-30 17:35:28.992 +0000]')
t.same(asString, '[17:35:28.992]')
t.same(asNumber, '[17:35:28.992]')
t.same(invalid, '[2 days ago]')

@@ -386,0 +388,0 @@ })

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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