Socket
Socket
Sign inDemoInstall

pino-pretty

Package Overview
Dependencies
Maintainers
3
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 11.0.0 to 11.1.0

10

index.d.ts

@@ -74,2 +74,4 @@ // Type definitions for pino-pretty 7.0

* @default "msg"
*
* Not required when used with pino >= 8.21.0
*/

@@ -126,2 +128,4 @@ messageKey?: string;

* @default ["err", "error"]
*
* Not required to handle custom errorKey when used with pino >= 8.21.0
*/

@@ -197,2 +201,4 @@ errorLikeObjectKeys?: string[];

* @example ( Object ) customLevels: { info: 10, some_level: 40 }
*
* Not required when used with pino >= 8.21.0
*/

@@ -213,2 +219,3 @@ customLevels?: string|object;

declare function build(options: PrettyOptions_): PinoPretty.PrettyStream;
type isColorSupported = PinoPretty.isColorSupported

@@ -225,5 +232,6 @@ declare namespace PinoPretty {

type Build = typeof build;
type isColorSupported = typeof Colorette.isColorSupported;
}
export default PinoPretty;
export { build, PinoPretty, PrettyOptions_ as PrettyOptions, colorizerFactory, prettyFactory };
export { build, PinoPretty, PrettyOptions_ as PrettyOptions, colorizerFactory, prettyFactory, isColorSupported };

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

function build (opts = {}) {
const pretty = prettyFactory(opts)
let pretty = prettyFactory(opts)
return abstractTransport(function (source) {
source.on('message', function pinoConfigListener (message) {
if (!message || message.code !== 'PINO_CONFIG') return
Object.assign(opts, {
messageKey: message.config.messageKey,
errorLikeObjectKeys: Array.from(new Set([...(opts.errorLikeObjectKeys || ERROR_LIKE_KEYS), message.config.errorKey])),
customLevels: message.config.levels.values
})
pretty = prettyFactory(opts)
source.off('message', pinoConfigListener)
})
const stream = new Transform({

@@ -172,2 +182,3 @@ objectMode: true,

module.exports.colorizerFactory = colors
module.exports.isColorSupported = isColorSupported
module.exports.default = build

2

lib/pretty.js

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

// pino@7+ does not log this anymore
if (log.type === 'Error' && log.stack) {
if (log.type === 'Error' && typeof log.stack === 'string') {
const prettifiedErrorLog = prettifyErrorLog({ log, context: this.context })

@@ -144,0 +144,0 @@ if (this.singleLine) line += this.EOL

{
"name": "pino-pretty",
"version": "11.0.0",
"version": "11.1.0",
"description": "Prettifier for Pino log lines",

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

"dateformat": "^4.6.3",
"fast-copy": "^3.0.0",
"fast-copy": "^3.0.2",
"fast-safe-stringify": "^2.1.1",

@@ -50,3 +50,3 @@ "help-me": "^5.0.0",

"secure-json-parse": "^2.4.0",
"sonic-boom": "^3.0.0",
"sonic-boom": "^4.0.1",
"strip-json-comments": "^3.1.1"

@@ -57,9 +57,10 @@ },

"fastbench": "^1.0.1",
"pino": "^8.0.0",
"pino": "^9.0.0",
"pre-commit": "^1.2.2",
"rimraf": "^3.0.2",
"semver": "^7.6.0",
"snazzy": "^9.0.0",
"standard": "^17.0.0",
"tap": "^16.0.0",
"tsd": "^0.30.0",
"tsd": "^0.31.0",
"typescript": "^5.0.2"

@@ -66,0 +67,0 @@ },

@@ -233,2 +233,15 @@ <a id="intro"></a>

### Checking color support in TTY
This boolean returns whether the currently used TTY supports colorizing the logs.
```js
import pretty from 'pino-pretty'
if (pretty.isColorSupported) {
...
}
```
<a id="options"></a>

@@ -244,6 +257,6 @@ ### Options

crlf: false, // --crlf
errorLikeObjectKeys: ['err', 'error'], // --errorLikeObjectKeys
errorLikeObjectKeys: ['err', 'error'], // --errorLikeObjectKeys (not required to match custom errorKey with pino >=8.21.0)
errorProps: '', // --errorProps
levelFirst: false, // --levelFirst
messageKey: 'msg', // --messageKey
messageKey: 'msg', // --messageKey (not required with pino >=8.21.0)
levelKey: 'level', // --levelKey

@@ -258,3 +271,3 @@ messageFormat: false, // --messageFormat

customColors: 'err:red,info:blue', // --customColors
customLevels: 'err:99,info:1', // --customLevels
customLevels: 'err:99,info:1', // --customLevels (not required with pino >=8.21.0)
levelLabel: 'levelLabel', // --levelLabel

@@ -261,0 +274,0 @@ minimumLevel: 'info', // --minimumLevel

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

const fs = require('fs')
const semver = require('semver')
const pinoPretty = require('..')

@@ -31,2 +32,5 @@ const SonicBoom = require('sonic-boom')

const Empty = function () {}
Empty.prototype = Object.create(null)
// All dates are computed from 'Fri, 30 Mar 2018 17:35:28 GMT'

@@ -923,2 +927,28 @@ const epoch = 1522431328992

t.test('log error-like object', (t) => {
t.plan(7)
const expectedLines = [
' type: "Error"',
' message: "m"',
' stack: [',
' "line1",',
' "line2"',
' ]'
]
const pretty = prettyFactory()
const log = pino({}, new Writable({
write (chunk, enc, cb) {
const formatted = pretty(chunk.toString())
const lines = formatted.split('\n')
t.equal(lines.length, expectedLines.length + 2)
lines.shift(); lines.pop()
for (let i = 0; i < lines.length; i += 1) {
t.equal(lines[i], expectedLines[i])
}
cb()
}
}))
log.error({ type: 'Error', message: 'm', stack: ['line1', 'line2'] })
})
t.test('include should override ignore', (t) => {

@@ -931,2 +961,18 @@ t.plan(1)

t.test('inlude a single key with null object', (t) => {
t.plan(1)
const pretty = prettyFactory({ include: 'level' })
const obj = new Empty()
obj.nested = 'property'
const arst = pretty({
msg: 'hello world',
pid: `${pid}`,
hostname,
time: epoch,
obj,
level: 30
})
t.equal(arst, 'INFO: hello world\n')
})
t.test('prettifies trace caller', (t) => {

@@ -1062,3 +1108,3 @@ t.plan(1)

const tmpDir = path.join(__dirname, '.tmp_' + Date.now())
t.teardown(() => rimraf(tmpDir, noop))
t.teardown(() => rimraf.sync(tmpDir))

@@ -1091,20 +1137,24 @@ const destination = join(tmpDir, 'output')

const tmpDir = path.join(__dirname, '.tmp_' + Date.now())
t.teardown(() => rimraf(tmpDir, noop))
t.teardown(() => rimraf.sync(tmpDir))
const destination = join(tmpDir, 'output')
const pretty = pinoPretty({
singleLine: true,
colorize: false,
mkdir: true,
append: false,
sync: true,
destination
})
const log = pino(pretty)
log.info({ msg: 'message', extra: { foo: 'bar', number: 42 }, upper: 'foobar' })
const log = pino(pino.transport({
target: '..',
options: {
singleLine: true,
colorize: false,
mkdir: true,
append: false,
sync: true,
destination
}
}))
log.info({ msg: 'message', extra: { foo: 'bar', number: 43 }, upper: 'foobar' })
await watchFileCreated(destination)
const formatted = fs.readFileSync(destination, 'utf8')
t.equal(formatted, `[${formattedEpoch}] INFO (${pid}): message {"extra":{"foo":"bar","number":42},"upper":"foobar"}\n`)
t.equal(formatted, `[${formattedEpoch}] INFO (${pid}): message {"extra":{"foo":"bar","number":43},"upper":"foobar"}\n`)
})

@@ -1138,5 +1188,64 @@

t.test('check support for colors', (t) => {
t.plan(1)
const isColorSupported = pinoPretty.isColorSupported
t.type(isColorSupported, 'boolean')
})
t.end()
})
if (semver.gte(pino.version, '8.21.0')) {
test('using pino config', (t) => {
t.beforeEach(() => {
Date.originalNow = Date.now
Date.now = () => epoch
})
t.afterEach(() => {
Date.now = Date.originalNow
delete Date.originalNow
})
t.test('can use different message keys', (t) => {
t.plan(1)
const destination = new Writable({
write (formatted, enc, cb) {
t.equal(
formatted.toString(),
`[${formattedEpoch}] INFO (${pid}): baz\n`
)
cb()
}
})
const pretty = pinoPretty({
destination,
colorize: false
})
const log = pino({ messageKey: 'bar' }, pretty)
log.info({ bar: 'baz' })
})
t.test('handles customLogLevels', (t) => {
t.plan(1)
const destination = new Writable({
write (formatted, enc, cb) {
t.equal(
formatted.toString(),
`[${formattedEpoch}] TESTCUSTOM (${pid}): test message\n`
)
cb()
}
})
const pretty = pinoPretty({
destination,
colorize: false
})
const log = pino({ customLevels: { testCustom: 35 } }, pretty)
log.testCustom('test message')
})
t.end()
})
}
function watchFileCreated (filename) {

@@ -1162,3 +1271,1 @@ return new Promise((resolve, reject) => {

}
function noop () {}

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

const pino = require('pino')
const semver = require('semver')
const serializers = pino.stdSerializers
const _prettyFactory = require('../').prettyFactory
const pinoPretty = require('../')
const _prettyFactory = pinoPretty.prettyFactory

@@ -456,1 +458,44 @@ function prettyFactory (opts) {

})
if (semver.gte(pino.version, '8.21.0')) {
test('using pino config', (t) => {
t.beforeEach(() => {
Date.originalNow = Date.now
Date.now = () => epoch
})
t.afterEach(() => {
Date.now = Date.originalNow
delete Date.originalNow
})
t.test('prettifies Error in custom errorKey', (t) => {
t.plan(8)
const destination = new Writable({
write (chunk, enc, cb) {
const formatted = chunk.toString()
const lines = formatted.split('\n')
t.equal(lines.length, expected.length + 7)
t.equal(lines[0], `[${formattedEpoch}] INFO (${pid}): hello world`)
t.match(lines[1], /\s{4}customErrorKey: {/)
t.match(lines[2], /\s{6}"type": "Error",/)
t.match(lines[3], /\s{6}"message": "hello world",/)
t.match(lines[4], /\s{6}"stack":/)
t.match(lines[5], /\s{6}Error: hello world/)
// Node 12 labels the test `<anonymous>`
t.match(lines[6], /\s{10}(at Test.t.test|at Test.<anonymous>)/)
cb()
}
})
const pretty = pinoPretty({
destination,
colorize: false
})
const log = pino({ errorKey: 'customErrorKey' }, pretty)
const err = Error('hello world')
const expected = err.stack.split('\n')
log.info({ customErrorKey: err })
})
t.end()
})
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc