pino-pretty
Advanced tools
Comparing version 11.1.0 to 11.2.0
@@ -24,3 +24,3 @@ 'use strict' | ||
function prettifyMetadata ({ log, context }) { | ||
const prettifiers = context.customPrettifiers | ||
const { customPrettifiers: prettifiers, colorizer } = context | ||
let line = '' | ||
@@ -32,7 +32,11 @@ | ||
if (log.name) { | ||
line += prettifiers.name ? prettifiers.name(log.name) : log.name | ||
line += prettifiers.name | ||
? prettifiers.name(log.name, 'name', log, { colors: colorizer.colors }) | ||
: log.name | ||
} | ||
if (log.pid) { | ||
const prettyPid = prettifiers.pid ? prettifiers.pid(log.pid) : log.pid | ||
const prettyPid = prettifiers.pid | ||
? prettifiers.pid(log.pid, 'pid', log, { colors: colorizer.colors }) | ||
: log.pid | ||
if (log.name && log.pid) { | ||
@@ -48,3 +52,7 @@ line += '/' + prettyPid | ||
// the leading space. | ||
line += `${line === '(' ? 'on' : ' on'} ${prettifiers.hostname ? prettifiers.hostname(log.hostname) : log.hostname}` | ||
const prettyHostname = prettifiers.hostname | ||
? prettifiers.hostname(log.hostname, 'hostname', log, { colors: colorizer.colors }) | ||
: log.hostname | ||
line += `${line === '(' ? 'on' : ' on'} ${prettyHostname}` | ||
} | ||
@@ -56,3 +64,7 @@ | ||
if (log.caller) { | ||
line += `${line === '' ? '' : ' '}<${prettifiers.caller ? prettifiers.caller(log.caller) : log.caller}>` | ||
const prettyCaller = prettifiers.caller | ||
? prettifiers.caller(log.caller, 'caller', log, { colors: colorizer.colors }) | ||
: log.caller | ||
line += `${line === '' ? '' : ' '}<${prettyCaller}>` | ||
} | ||
@@ -59,0 +71,0 @@ |
@@ -5,4 +5,8 @@ 'use strict' | ||
const prettifyMetadata = require('./prettify-metadata') | ||
const getColorizer = require('../colors') | ||
const context = { | ||
customPrettifiers: {} | ||
customPrettifiers: {}, | ||
colorizer: { | ||
colors: {} | ||
} | ||
} | ||
@@ -108,3 +112,4 @@ | ||
context: { | ||
customPrettifiers: prettifiers | ||
customPrettifiers: prettifiers, | ||
colorizer: { colors: {} } | ||
} | ||
@@ -114,1 +119,34 @@ }) | ||
}) | ||
tap.test('uses colorizer from passed context to colorize metadata', async t => { | ||
const prettifiers = { | ||
name (input, _key, _log, { colors }) { | ||
return colors.blue(input) | ||
}, | ||
pid (input, _key, _log, { colors }) { | ||
return colors.red(input) | ||
}, | ||
hostname (input, _key, _log, { colors }) { | ||
return colors.green(input) | ||
}, | ||
caller (input, _key, _log, { colors }) { | ||
return colors.cyan(input) | ||
} | ||
} | ||
const log = { name: 'foo', pid: '1234', hostname: 'bar', caller: 'baz' } | ||
const colorizer = getColorizer(true) | ||
const context = { | ||
customPrettifiers: prettifiers, | ||
colorizer | ||
} | ||
const result = prettifyMetadata({ log, context }) | ||
const colorizedName = colorizer.colors.blue(log.name) | ||
const colorizedPid = colorizer.colors.red(log.pid) | ||
const colorizedHostname = colorizer.colors.green(log.hostname) | ||
const colorizedCaller = colorizer.colors.cyan(log.caller) | ||
const expected = `(${colorizedName}/${colorizedPid} on ${colorizedHostname}) <${colorizedCaller}>` | ||
t.equal(result, expected) | ||
}) |
{ | ||
"name": "pino-pretty", | ||
"version": "11.1.0", | ||
"version": "11.2.0", | ||
"description": "Prettifier for Pino log lines", | ||
@@ -5,0 +5,0 @@ "type": "commonjs", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
235265
5794