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 5.1.1 to 5.1.2

21

index.d.ts

@@ -102,2 +102,23 @@ // Type definitions for pino-pretty 4.7

ignore?: string;
/**
* Provides the ability to add a custom prettify function for specific log properties.
* `customPrettifiers` is an object, where keys are log properties that will be prettified
* and value is the prettify function itself.
* For example, if a log line contains a query property, you can specify a prettifier for it:
* @default {}
*
* @example
* ```typescript
* {
* customPrettifiers: {
* query: prettifyQuery
* }
* }
* //...
* const prettifyQuery = value => {
* // do some prettify magic
* }
* ```
*/
customPrettifiers?: Record<string, PinoPretty.Prettifier>;
}

@@ -104,0 +125,0 @@

52

lib/utils.js

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

deleteLogProperty,
splitIgnoreKey,
createDate,

@@ -484,2 +485,48 @@ isValidDate

/**
* Splits the input key delimited by a dot character but not when it is preceded
* by a backslash.
*
* @param {string} key A string identifying the property.
*
* @returns {string[]} Returns a list of string containing each delimited property.
* e.g. `'prop2\.domain\.corp.prop2'` should return [ 'prop2.domain.com', 'prop2' ]
*/
function splitIgnoreKey (key) {
const result = []
let backslash = false
let segment = ''
for (let i = 0; i < key.length; i++) {
const c = key.charAt(i)
if (c === '\\') {
backslash = true
continue
}
if (backslash) {
backslash = false
segment += c
continue
}
/* Non-escaped dot, push to result */
if (c === '.') {
result.push(segment)
segment = ''
continue
}
segment += c
}
/* Push last entry to result */
if (segment.length) {
result.push(segment)
}
return result
}
/**
* Deletes a specified property from a log object if it exists.

@@ -491,6 +538,7 @@ * This function mutates the passed in `log` object.

* the log object. Accepts nested properties delimited by a `.`
* e.g. `'prop1.prop2'`.
* Delimiter can be escaped to preserve property names that contain the delimiter.
* e.g. `'prop1.prop2'` or `'prop2\.domain\.corp.prop2'`
*/
function deleteLogProperty (log, property) {
const props = property.split('.')
const props = splitIgnoreKey(property)
const propToDelete = props.pop()

@@ -497,0 +545,0 @@

2

package.json
{
"name": "pino-pretty",
"version": "5.1.1",
"version": "5.1.2",
"description": "Prettifier for Pino log lines",

@@ -5,0 +5,0 @@ "type": "commonjs",

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

[jmespath](http://jmespath.org/).
- `--ignore` (`-i`): Ignore one or several keys, nested keys are supported: (`-i time,hostname,req.headers`)
- `--ignore` (`-i`): Ignore one or several keys, nested keys are supported with each property delimited by a dot character (`.`),
keys may be escaped to target property names that contains the delimiter itself:
(`-i time,hostname,req.headers,log\\.domain\\.corp/foo`)
- `--hideObject` (`-H`): Hide objects from output (but not error object)

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

@@ -85,2 +85,15 @@ 'use strict'

t.test('does ignore escaped keys', (t) => {
t.plan(1)
const env = { TERM: 'dumb' }
const child = spawn(process.argv[0], [bin, '-i', 'log\\.domain\\.corp/foo'], { env })
child.on('error', t.threw)
child.stdout.on('data', (data) => {
t.equal(data.toString(), '[1522431328992] INFO: hello world\n')
})
const logLine = '{"level":30,"time":1522431328992,"msg":"hello world","log.domain.corp/foo":"bar"}\n'
child.stdin.write(logLine)
t.teardown(() => child.kill())
})
t.test('passes through stringified date as string', (t) => {

@@ -87,0 +100,0 @@ t.plan(1)

@@ -162,1 +162,30 @@ 'use strict'

})
tap.test('#splitIgnoreKey', t => {
t.test('splitIgnoreKey does not change key', async t => {
const result = internals.splitIgnoreKey('data1')
t.same(result, ['data1'])
})
t.test('splitIgnoreKey splits nested key', async t => {
const result = internals.splitIgnoreKey('data1.data2.data-3')
t.same(result, ['data1', 'data2', 'data-3'])
})
t.test('splitIgnoreKey splits nested keys ending with a dot', async t => {
const result = internals.splitIgnoreKey('data1.data2.data-3.')
t.same(result, ['data1', 'data2', 'data-3'])
})
t.test('splitIgnoreKey splits nested escaped key', async t => {
const result = internals.splitIgnoreKey('logging\\.domain\\.corp/operation.foo.bar-2')
t.same(result, ['logging.domain.corp/operation', 'foo', 'bar-2'])
})
t.test('splitIgnoreKey splits nested escaped key with special characters', async t => {
const result = internals.splitIgnoreKey('logging\\.domain\\.corp/operation.!\t@#$%^&*()_+=-<>.bar\\.2')
t.same(result, ['logging.domain.corp/operation', '!\t@#$%^&*()_+=-<>', 'bar.2'])
})
t.end()
})

@@ -385,2 +385,19 @@ 'use strict'

const logData2 = Object.assign({
'logging.domain.corp/operation': {
id: 'foo',
producer: 'bar'
}
}, logData)
t.test('filterLog removes entry with escape sequence', async t => {
const result = filterLog(logData2, ['data1', 'logging\\.domain\\.corp/operation'])
t.same(result, { level: 30, time: 1522431328992 })
})
t.test('filterLog removes entry with escape sequence nested', async t => {
const result = filterLog(logData2, ['data1', 'logging\\.domain\\.corp/operation.producer'])
t.same(result, { level: 30, time: 1522431328992, 'logging.domain.corp/operation': { id: 'foo' } })
})
t.end()

@@ -387,0 +404,0 @@ })

@@ -27,2 +27,7 @@ import prettyFactory from "../../";

singleLine: false,
customPrettifiers: {
key: (value) => {
return value.toString().toUpperCase();
}
}
};

@@ -46,2 +51,7 @@

singleLine: false,
customPrettifiers: {
key: (value) => {
return value.toString().toUpperCase();
}
}
};

@@ -48,0 +58,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