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 9.1.1 to 9.2.0

9

index.d.ts

@@ -178,2 +178,11 @@ // Type definitions for pino-pretty 7.0

customPrettifiers?: Record<string, PinoPretty.Prettifier>;
/**
* Change the level names and values to an user custom preset.
*
* Can be a CSV string in 'level_name:level_value' format or an object.
*
* @example ( CSV ) customLevels: 'info:10,some_level:40'
* @example ( Object ) customLevels: { info: 10, some_level: 40 }
*/
customLevels?: string|object;
}

@@ -180,0 +189,0 @@

27

index.js

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

buildSafeSonicBoom,
filterLog
filterLog,
handleCustomlevelsOpts,
handleCustomlevelNamesOpts
} = require('./lib/utils')

@@ -66,24 +68,5 @@

const useOnlyCustomProps = typeof opts.useOnlyCustomProps === 'boolean' ? opts.useOnlyCustomProps : opts.useOnlyCustomProps === 'true'
const customLevels = opts.customLevels
? opts.customLevels
.split(',')
.reduce((agg, value, idx) => {
const [levelName, levelIdx = idx] = value.split(':')
const customLevels = handleCustomlevelsOpts(opts.customLevels)
const customLevelNames = handleCustomlevelNamesOpts(opts.customLevels)
agg[levelIdx] = levelName.toUpperCase()
return agg
}, { default: 'USERLVL' })
: {}
const customLevelNames = opts.customLevels
? opts.customLevels
.split(',')
.reduce((agg, value, idx) => {
const [levelName, levelIdx = idx] = value.split(':')
agg[levelName.toLowerCase()] = levelIdx
return agg
}, {})
: {}
const customColors = opts.customColors

@@ -90,0 +73,0 @@ ? opts.customColors

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

buildSafeSonicBoom,
filterLog
filterLog,
handleCustomlevelsOpts,
handleCustomlevelNamesOpts
}

@@ -673,1 +675,72 @@

}
/**
* Parse a CSV string or options object that specifies
* configuration for custom levels.
*
* @param {string|object} cLevels An object mapping level
* names to values, e.g. `{ info: 30, debug: 65 }`, or a
* CSV string in the format `level_name:level_value`, e.g.
* `info:30,debug:65`.
*
* @returns {object} An object mapping levels to labels that
* appear in logs, e.g. `{ '30': 'INFO', '65': 'DEBUG' }`.
*/
function handleCustomlevelsOpts (cLevels) {
if (!cLevels) return {}
if (typeof cLevels === 'string') {
return cLevels
.split(',')
.reduce((agg, value, idx) => {
const [levelName, levelIdx = idx] = value.split(':')
agg[levelIdx] = levelName.toUpperCase()
return agg
},
{ default: 'USERLVL' })
} else if (Object.prototype.toString.call(cLevels) === '[object Object]') {
return Object
.keys(cLevels)
.reduce((agg, levelName, idx) => {
agg[cLevels[levelName]] = levelName.toUpperCase()
return agg
}, { default: 'USERLVL' })
} else {
return {}
}
}
/**
* Parse a CSV string or options object that maps level
* labels to level values.
*
* @param {string|object} cLevels An object mapping level
* names to level values, e.g. `{ info: 30, debug: 65 }`, or a
* CSV string in the format `level_name:level_value`, e.g.
* `info:30,debug:65`.
*
* @returns {object} An object mapping levels names to level values
* e.g. `{ info: 30, debug: 65 }`.
*/
function handleCustomlevelNamesOpts (cLevels) {
if (!cLevels) return {}
if (typeof cLevels === 'string') {
return cLevels
.split(',')
.reduce((agg, value, idx) => {
const [levelName, levelIdx = idx] = value.split(':')
agg[levelName.toLowerCase()] = levelIdx
return agg
}, {})
} else if (Object.prototype.toString.call(cLevels) === '[object Object]') {
return Object
.keys(cLevels)
.reduce((agg, levelName, idx) => {
agg[levelName.toLowerCase()] = cLevels[levelName]
return agg
}, {})
} else {
return {}
}
}
{
"name": "pino-pretty",
"version": "9.1.1",
"version": "9.2.0",
"description": "Prettifier for Pino log lines",

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

"tap": "^16.0.0",
"tsd": "^0.24.1",
"tsd": "^0.25.0",
"typescript": "^4.4.3"

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

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

singleLine: false, // --singleLine
config: '/path/to/config/', // --config
customColors: 'err:red,info:blue', // --customColors
customLevels: 'err:99,info:1', // --customLevels
levelLabel: 'levelLabel', // --levelLabel
minimumLevel: 'info', // --minimumLevel
useOnlyCustomProps: true, // --useOnlyCustomProps
// The file or file descriptor (1 is stdout) to write to

@@ -254,0 +259,0 @@ destination: 1,

@@ -552,1 +552,69 @@ 'use strict'

})
tap.test('handleCustomlevelsOpts', t => {
const { handleCustomlevelsOpts } = utils
t.test('returns a empty object `{}` for unknown parameter', async t => {
const handledCustomLevel = handleCustomlevelsOpts(123)
t.same(handledCustomLevel, {})
})
t.test('returns a filled object for string parameter', async t => {
const handledCustomLevel = handleCustomlevelsOpts('ok:10,warn:20,error:35')
t.same(handledCustomLevel, {
10: 'OK',
20: 'WARN',
35: 'ERROR',
default: 'USERLVL'
})
})
t.test('returns a filled object for object parameter', async t => {
const handledCustomLevel = handleCustomlevelsOpts({
ok: 10,
warn: 20,
error: 35
})
t.same(handledCustomLevel, {
10: 'OK',
20: 'WARN',
35: 'ERROR',
default: 'USERLVL'
})
})
t.end()
})
tap.test('handleCustomlevelNamesOpts', t => {
const { handleCustomlevelNamesOpts } = utils
t.test('returns a empty object `{}` for unknown parameter', async t => {
const handledCustomLevelNames = handleCustomlevelNamesOpts(123)
t.same(handledCustomLevelNames, {})
})
t.test('returns a filled object for string parameter', async t => {
const handledCustomLevelNames = handleCustomlevelNamesOpts('ok:10,warn:20,error:35')
t.same(handledCustomLevelNames, {
ok: 10,
warn: 20,
error: 35
})
})
t.test('returns a filled object for object parameter', async t => {
const handledCustomLevelNames = handleCustomlevelNamesOpts({
ok: 10,
warn: 20,
error: 35
})
t.same(handledCustomLevelNames, {
ok: 10,
warn: 20,
error: 35
})
})
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

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc