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.0.0 to 8.1.0

help/help.txt

87

bin.js
#!/usr/bin/env node
const fs = require('fs')
const args = require('args')
const path = require('path')
const help = require('help-me')({
dir: path.join(__dirname, 'help'),
ext: '.txt'
})
const pump = require('pump')

@@ -14,2 +17,3 @@ const sjp = require('secure-json-parse')

const { isObject } = require('./lib/utils')
const minimist = require('minimist')

@@ -31,53 +35,34 @@ const parseJSON = input => {

args
.option(['c', 'colorize'], 'Force adding color sequences to the output')
.option(['f', 'crlf'], 'Append CRLF instead of LF to formatted lines')
.option(['e', 'errorProps'], 'Comma separated list of properties on error objects to show (`*` for all properties) (defaults to ``)')
.option(['l', 'levelFirst'], 'Display the log level as the first output field')
.option(['L', 'minimumLevel'], 'Hide messages below the specified log level')
.option(['x', 'customLevels'], 'Override default levels (`-x err:99,info:1`)')
.option(['X', 'customColors'], 'Override default colors using names from https://www.npmjs.com/package/colorette (`-X err:red,info:blue`)')
.option(['U', 'useOnlyCustomProps'], 'Only use custom levels and colors (if provided); don\'t fallback to default levels and colors (-U false)')
.option(['k', 'errorLikeObjectKeys'], 'Define which keys contain error objects (`-k err,error`) (defaults to `err,error`)')
.option(['m', 'messageKey'], 'Highlight the message under the specified key', CONSTANTS.MESSAGE_KEY)
.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')
.option(['a', 'timestampKey'], 'Display the timestamp from the specified key', CONSTANTS.TIMESTAMP_KEY)
.option(['t', 'translateTime'], 'Display epoch timestamps as UTC ISO format or according to an optional format string (default ISO 8601)')
.option(['i', 'ignore'], 'Ignore one or several keys: (`-i time,hostname`)')
.option(['H', 'hideObject'], 'Hide objects from output (but not error object)')
.option(['S', 'singleLine'], 'Print all non-error objects on a single line')
.option('config', 'specify a path to a json file containing the pino-pretty options')
const cmd = minimist(process.argv.slice(2))
args
.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\'')
.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')
.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')
.example('cat log | pino-pretty -l', 'To flip level and time/date in standard output use the -l option')
.example('cat log | pino-pretty -L info', 'Only prints messages with a minimum log level of info')
.example('cat log | pino-pretty -i pid,hostname', 'Prettify logs but don\'t print pid and hostname')
.example('cat log | pino-pretty --config=/path/to/config.json', 'Loads options from a config file')
helper(cmd)
const DEFAULT_VALUE = '\0default'
let opts = args.parse(process.argv, {
mri: {
default: {
messageKey: DEFAULT_VALUE,
minimumLevel: DEFAULT_VALUE,
levelKey: DEFAULT_VALUE,
timestampKey: DEFAULT_VALUE
},
// NOTE: The following key-value pairs values should be in sync with the
// short version values defined in each `args.option([value, key], ...)`
alias: {
messageKey: 'm',
minimumLevel: 'L',
timestampKey: 'a'
}
let opts = minimist(process.argv, {
alias: {
colorize: 'c',
crlf: 'f',
errorProps: 'e',
levelFirst: 'l',
minimumLevel: 'L',
customLevels: 'x',
customColors: 'X',
useOnlyCustomProps: 'U',
errorLikeObjectKeys: 'k',
messageKey: 'm',
levelKey: CONSTANTS.LEVEL_KEY,
levelLabel: 'b',
messageFormat: 'o',
timestampKey: 'a',
translateTime: 't',
ignore: 'i',
hideObject: 'H',
singleLine: 'S'
},
default: {
messageKey: DEFAULT_VALUE,
minimumLevel: DEFAULT_VALUE,
levelKey: DEFAULT_VALUE,
timestampKey: DEFAULT_VALUE
}

@@ -126,1 +111,7 @@ })

}
function helper (cmd) {
if (cmd.h || cmd.help) {
help.toStdout()
}
}

@@ -12,3 +12,3 @@ // Type definitions for pino-pretty 7.0

// @ts-ignore fall back to any if pino is not available, i.e. when running pino tests
import { DestinationStream } from 'pino';
import { DestinationStream, Level } from 'pino';

@@ -66,2 +66,7 @@ type LogDescriptor = Record<string, unknown>;

/**
* The minimum log level to include in the output.
* @default "trace"
*/
minimumLevel?: Level;
/**
* Format output of message, e.g. {level} - {pid} will output message: INFO - 1123

@@ -68,0 +73,0 @@ * @default false

@@ -65,36 +65,36 @@ 'use strict'

? opts.customLevels
.split(',')
.reduce((agg, value, idx) => {
const [levelName, levelIdx = idx] = value.split(':')
.split(',')
.reduce((agg, value, idx) => {
const [levelName, levelIdx = idx] = value.split(':')
agg[levelIdx] = levelName.toUpperCase()
agg[levelIdx] = levelName.toUpperCase()
return agg
}, { default: 'USERLVL' })
return agg
}, { default: 'USERLVL' })
: {}
const customLevelNames = opts.customLevels
? opts.customLevels
.split(',')
.reduce((agg, value, idx) => {
const [levelName, levelIdx = idx] = value.split(':')
.split(',')
.reduce((agg, value, idx) => {
const [levelName, levelIdx = idx] = value.split(':')
agg[levelName.toLowerCase()] = levelIdx
agg[levelName.toLowerCase()] = levelIdx
return agg
}, {})
return agg
}, {})
: {}
const customColors = opts.customColors
? opts.customColors
.split(',')
.reduce((agg, value) => {
const [level, color] = value.split(':')
.split(',')
.reduce((agg, value) => {
const [level, color] = value.split(':')
const condition = useOnlyCustomProps ? opts.customLevels : customLevelNames[level] !== undefined
const levelNum = condition ? customLevelNames[level] : LEVEL_NAMES[level]
const colorIdx = levelNum !== undefined ? levelNum : level
const condition = useOnlyCustomProps ? opts.customLevels : customLevelNames[level] !== undefined
const levelNum = condition ? customLevelNames[level] : LEVEL_NAMES[level]
const colorIdx = levelNum !== undefined ? levelNum : level
agg.push([colorIdx, color])
agg.push([colorIdx, color])
return agg
}, [])
return agg
}, [])
: undefined

@@ -101,0 +101,0 @@ const customProps = {

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

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

"scripts": {
"ci": "standard && tap --color --coverage-report=lcovonly && npm run test-types",
"ci": "standard && tap --coverage-report=lcovonly && npm run test-types",
"lint": "standard | snazzy",

@@ -36,25 +36,26 @@ "test": "tap --100 --color",

"dependencies": {
"args": "5.0.1",
"colorette": "^2.0.7",
"dateformat": "^4.6.3",
"fast-copy": "^2.1.1",
"fast-safe-stringify": "^2.0.7",
"fast-safe-stringify": "^2.1.1",
"joycon": "^3.1.1",
"on-exit-leak-free": "^0.2.0",
"pino-abstract-transport": "^0.5.0",
"help-me": "^4.0.1",
"minimist": "^1.2.6",
"on-exit-leak-free": "^1.0.0",
"pino-abstract-transport": "^1.0.0",
"pump": "^3.0.0",
"readable-stream": "^3.6.0",
"readable-stream": "^4.0.0",
"secure-json-parse": "^2.4.0",
"sonic-boom": "^2.2.0",
"sonic-boom": "^3.0.0",
"strip-json-comments": "^3.1.1"
},
"devDependencies": {
"@types/node": "^17.0.0",
"pino": "^7.0.0",
"@types/node": "^18.0.0",
"pino": "^8.0.0",
"pre-commit": "^1.2.2",
"rimraf": "^3.0.2",
"snazzy": "^9.0.0",
"standard": "^16.0.3",
"standard": "^17.0.0",
"tap": "^16.0.0",
"tsd": "^0.20.0",
"tsd": "^0.21.0",
"typescript": "^4.4.3"

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

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

[![Build Status](https://img.shields.io/github/workflow/status/pinojs/pino-pretty/CI)](https://github.com/pinojs/pino-pretty/actions?query=workflow%3ACI)
[![Known Vulnerabilities](https://snyk.io/test/github/pinojs/pino-pretty/badge.svg)](https://snyk.io/test/github/pinojs/pino-pretty)
[![Coverage Status](https://img.shields.io/coveralls/github/pinojs/pino-pretty)](https://coveralls.io/github/pinojs/pino-pretty?branch=master)

@@ -81,3 +80,3 @@ [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)

- `--useOnlyCustomProps` (`-U`): Only use custom levels and colors (if provided) (default: true); else fallback to default levels and colors, e.g. `-U false`
- `--messageFormat` (`-o`): Format output of message, e.g. `{levelLabel} - {pid} - url:{request.url}` will output message: `INFO - 1123 - url:localhost:3000/test`
- `--messageFormat` (`-o`): Format output of message, e.g. `{levelLabel} - {pid} - url:{req.url}` will output message: `INFO - 1123 - url:localhost:3000/test`
Default: `false`

@@ -308,3 +307,3 @@ - `--timestampKey` (`-a`): Define the key that contains the log timestamp.

hostname: hostname => colorGreen(hostname)
pid: pid => colorRed(hostname)
pid: pid => colorRed(pid)
name: name => colorBlue(name)

@@ -333,3 +332,3 @@ caller: caller => colorCyan(caller)

{
messageFormat: '{levelLabel} - {pid} - url:{request.url}'
messageFormat: '{levelLabel} - {pid} - url:{req.url}'
}

@@ -336,0 +335,0 @@ ```

@@ -380,4 +380,4 @@ 'use strict'

base: {
name: name,
hostname: hostname
name,
hostname
}

@@ -405,3 +405,3 @@ }

base: {
name: name,
name,
pid: process.pid

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

base: {
hostname: hostname,
hostname,
pid: process.pid

@@ -432,0 +432,0 @@ }

@@ -188,5 +188,14 @@ 'use strict'

child.on('close', (code) => t.equal(code, 1))
child.stderr.on('data', (data) => {
t.equal(data.indexOf('Error: Failed to load runtime configuration file: pino-pretty.config.missing.json') >= 0, true)
child.stdout.pipe(process.stdout)
child.stderr.setEncoding('utf8')
let data = ''
child.stderr.on('data', (chunk) => {
data += chunk
})
child.on('close', function () {
t.equal(
data.toString().indexOf('Error: Failed to load runtime configuration file: pino-pretty.config.missing.json') >= 0,
true
)
})
t.teardown(() => child.kill())

@@ -202,3 +211,9 @@ })

child.on('close', (code) => t.equal(code, 1))
child.stderr.on('data', (data) => {
child.stdout.pipe(process.stdout)
child.stderr.setEncoding('utf8')
let data = ''
child.stderr.on('data', (chunk) => {
data += chunk
})
child.on('close', function () {
t.equal(data.indexOf('Error: Invalid runtime configuration file: pino-pretty.config.js') >= 0, true)

@@ -217,3 +232,9 @@ })

child.on('close', (code) => t.equal(code, 1))
child.stderr.on('data', (data) => {
child.stdout.pipe(process.stdout)
child.stderr.setEncoding('utf8')
let data = ''
child.stderr.on('data', (chunk) => {
data += chunk
})
child.on('close', function () {
t.equal(data.indexOf('Error: Invalid runtime configuration file: pino-pretty.config.invalid.js') >= 0, true)

@@ -224,3 +245,15 @@ })

t.test('test help', (t) => {
t.plan(1)
const env = { TERM: 'dumb' }
const child = spawn(process.argv[0], [bin, '--help'], { env })
const file = fs.readFileSync('help/help.txt').toString()
child.on('error', t.threw)
child.stdout.on('data', (data) => {
t.equal(data.toString(), file)
})
t.teardown(() => child.kill())
})
t.end()
})

@@ -426,6 +426,7 @@ 'use strict'

const expectedLines = [
'"type": "Error"',
'"message": "error message"',
'"stack": null',
'"some": "property"'
' "type": "Error",',
' "message": "error message",',
' "stack":',
' ',
' "some": "property"'
]

@@ -432,0 +433,0 @@ t.plan(expectedLines.length)

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

const result = filterLog(logData, [])
t.equals(logData.data1.error, result.data1.error)
t.equal(logData.data1.error, result.data1.error)
})

@@ -414,0 +414,0 @@

@@ -24,2 +24,3 @@ import { expectType } from "tsd";

timestampKey: "timestamp",
minimumLevel: "trace",
translateTime: "UTC:h:MM:ss TT Z",

@@ -51,2 +52,3 @@ singleLine: false,

timestampKey: "timestamp",
minimumLevel: "trace",
translateTime: "UTC:h:MM:ss TT Z",

@@ -53,0 +55,0 @@ singleLine: false,

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