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 4.7.1 to 4.8.0

8

docs/help.md

@@ -6,3 +6,3 @@ <a id="Systemd"></a>

For example viewing the pretified logs of a process named `monitor` with `journalctl -u monitor -f | pino-pretty`, might output something like this:
For example viewing the prettified logs of a process named `monitor` with `journalctl -u monitor -f | pino-pretty`, might output something like this:

@@ -13,4 +13,4 @@ ```

```
As you can see, the timestamp, hostname and pid are duplicated.
If you just want the bare pretified Pino logs you can strip out the duplicate items from the `journalctl` output with the `-o cat` option of `journalctl`:
As you can see, the timestamp, hostname, and pid are duplicated.
If you just want the bare prettified Pino logs you can strip out the duplicate items from the `journalctl` output with the `-o cat` option of `journalctl`:
```

@@ -23,5 +23,5 @@ journalctl -u monitor -f -o cat | pino-pretty

```
Making the output even more human readble by using the pino-pretty options `-t` to format the timestamp and `-i pid, hostname` to filter out hostname and pid:
Make the output even more human readable by using the pino-pretty options `-t` to format the timestamp and `-i pid, hostname` to filter out hostname and pid:
```
[2020-04-24 05:42:24.836 +0000] INFO : TT 21
```

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

prettifyObject,
prettifyTime
prettifyTime,
filterLog
} = require('./lib/utils')

@@ -85,8 +86,3 @@

if (ignoreKeys) {
log = Object.keys(log)
.filter(key => !ignoreKeys.has(key))
.reduce((res, key) => {
res[key] = log[key]
return res
}, {})
log = filterLog(log, ignoreKeys)
}

@@ -93,0 +89,0 @@

'use strict'
const clone = require('rfdc')()
const dateformat = require('dateformat')

@@ -24,3 +25,4 @@ const stringifySafe = require('fast-safe-stringify')

prettifyObject,
prettifyTime
prettifyTime,
filterLog
}

@@ -31,3 +33,4 @@

joinLinesWithIndentation,
prettifyError
prettifyError,
deleteLogProperty
}

@@ -440,1 +443,40 @@

}
/**
* Deletes a specified property from a log object if it exists.
* This function mutates the passed in `log` object.
*
* @param {object} log The log object to be modified.
* @param {string} property A string identifying the property to be deleted from
* the log object. Accepts nested properties delimited by a `.`
* e.g. `'prop1.prop2'`.
*/
function deleteLogProperty (log, property) {
const props = property.split('.')
const propToDelete = props.pop()
props.forEach((prop) => {
if (!Object.prototype.hasOwnProperty.call(log, prop)) {
return
}
log = log[prop]
})
delete log[propToDelete]
}
/**
* Filter a log object by removing any ignored keys.
*
* @param {object} log The log object to be modified.
* @param {string} ignoreKeys An array of strings identifying the properties to be removed.
*
* @returns {object} A new `log` object instance that does not include the ignored keys.
*/
function filterLog (log, ignoreKeys) {
const logCopy = clone(log)
ignoreKeys.forEach((ignoreKey) => {
deleteLogProperty(logCopy, ignoreKey)
})
return logCopy
}
{
"name": "pino-pretty",
"version": "4.7.1",
"version": "4.8.0",
"description": "Prettifier for Pino log lines",

@@ -41,2 +41,3 @@ "main": "index.js",

"readable-stream": "^3.6.0",
"rfdc": "^1.3.0",
"split2": "^3.1.1",

@@ -43,0 +44,0 @@ "strip-json-comments": "^3.1.1"

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

It's recommended to use `pino-pretty` with `pino`
It is recommended to use `pino-pretty` with `pino`
by piping output to the CLI tool:

@@ -63,3 +63,3 @@

- `--errorProps` (`-e`): When formatting an error object, display this list
of properties. The list should be a comma separated list of properties Default: `''`.
of properties. The list should be a comma-separated list of properties Default: `''`.
- `--levelFirst` (`-l`): Display the log level name before the logged date and time.

@@ -78,13 +78,13 @@ - `--errorLikeObjectKeys` (`-k`): Define the log keys that are associated with

Default: `time`.
- `--translateTime` (`-t`): Translate the epoch time value into a human readable
- `--translateTime` (`-t`): Translate the epoch time value into a human-readable
date and time string. This flag also can set the format string to apply when
translating the date to human readable format. For a list of available pattern
letters see the [`dateformat` documentation](https://www.npmjs.com/package/dateformat).
translating the date to a human-readable format. For a list of available pattern
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.
- Require a `SYS:` prefix to translate time to the local system's timezone. A
- Require a `SYS:` prefix to translate time to the local system's time zone. A
shortcut `SYS:standard` to translate time to `yyyy-mm-dd HH:MM:ss.l o` in
system timezone.
system time zone.
- `--search` (`-s`): Specify a search pattern according to
[jmespath](http://jmespath.org/).
- `--ignore` (`-i`): Ignore one or several keys: (`-i time,hostname`)
- `--ignore` (`-i`): Ignore one or several keys, nested keys are supported: (`-i time,hostname,req.headers`)
- `--hideObject` (`-H`): Hide objects from output (but not error object)

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

We recommend against using `pino-pretty` in production, and highly
We recommend against using `pino-pretty` in production and highly
recommend installing `pino-pretty` as a development dependency.

@@ -146,3 +146,3 @@

levelKey: 'level', // --levelKey
messageFormat: false // --messageFormat
messageFormat: false, // --messageFormat
timestampKey: 'time', // --timestampKey

@@ -163,3 +163,3 @@ translateTime: false, // --translateTime

for specific log properties. `customPrettifiers` is an object, where keys are
log properties which will be prettified and value is the prettify function itself.
log properties that will be prettified and value is the prettify function itself.
For example, if a log line contains a `query` property,

@@ -179,3 +179,3 @@ you can specify a prettifier for it:

`messageFormat` option allows you to customize the message output. The format can be defined by a template `string` like this:
`messageFormat` option allows you to customize the message output. A template `string` like this can define the format:
```js

@@ -186,3 +186,3 @@ {

```
But this option can also be defined as a `function` with this prototype:
This option can also be defined as a `function` with this prototype:
```js

@@ -189,0 +189,0 @@ {

@@ -136,3 +136,26 @@ 'use strict'

t.test('does ignore nested keys', (t) => {
t.plan(1)
const logLineNested = JSON.stringify(Object.assign(JSON.parse(logLine), {
extra: {
foo: 'bar',
number: 42,
nested: {
foo2: 'bar2'
}
}
})) + '\n'
const env = { TERM: 'dumb' }
const child = spawn(process.argv[0], [bin, '-S', '-i', 'extra.foo,extra.nested,extra.nested.miss'], { env })
child.on('error', t.threw)
child.stdout.on('data', (data) => {
t.is(data.toString(), `[${epoch}] INFO (42 on foo): hello world {"extra":{"number":42}}\n`)
})
child.stdin.write(logLineNested)
t.tearDown(() => child.kill())
})
t.end()
})
'use strict'
const tap = require('tap')
const clone = require('rfdc')()
const stringifySafe = require('fast-safe-stringify')

@@ -98,1 +99,30 @@ const { internals } = require('../../lib/utils')

})
tap.test('#deleteLogProperty', t => {
const logData = {
level: 30,
data1: {
data2: { 'data-3': 'bar' }
}
}
t.test('deleteLogProperty deletes property of depth 1', async t => {
const log = clone(logData)
internals.deleteLogProperty(log, 'data1')
t.same(log, { level: 30 })
})
t.test('deleteLogProperty deletes property of depth 2', async t => {
const log = clone(logData)
internals.deleteLogProperty(log, 'data1.data2')
t.same(log, { level: 30, data1: { } })
})
t.test('deleteLogProperty deletes property of depth 3', async t => {
const log = clone(logData)
internals.deleteLogProperty(log, 'data1.data2.data-3')
t.same(log, { level: 30, data1: { data2: { } } })
})
t.end()
})

@@ -344,1 +344,24 @@ 'use strict'

})
tap.test('#filterLog', t => {
const { filterLog } = utils
const logData = {
level: 30,
time: 1522431328992,
data1: {
data2: { 'data-3': 'bar' }
}
}
t.test('filterLog removes single entry', async t => {
const result = filterLog(logData, ['data1.data2.data-3'])
t.same(result, { level: 30, time: 1522431328992, data1: { data2: { } } })
})
t.test('filterLog removes multiple entries', async t => {
const result = filterLog(logData, ['time', 'data1'])
t.same(result, { level: 30 })
})
t.end()
})

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