Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: gray out meta data object when using --singleLine=true #161

Merged
merged 5 commits into from
Mar 5, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const dateformat = require('dateformat')
const stringifySafe = require('fast-safe-stringify')
const defaultColorizer = require('./colors')()
const chalk = require('chalk')
jsumners marked this conversation as resolved.
Show resolved Hide resolved
const {
DATE_FORMAT,
ERROR_LIKE_KEYS,
Expand Down Expand Up @@ -334,7 +335,7 @@ function prettifyObject ({
if (singleLine) {
// Stringify the entire object as a single JSON line
if (Object.keys(plain).length > 0) {
result += stringifySafe(plain)
result += chalk.grey(stringifySafe(plain))
}
result += eol
} else {
Expand Down
3 changes: 2 additions & 1 deletion test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const test = require('tap').test
const pino = require('pino')
const dateformat = require('dateformat')
const _prettyFactory = require('../')
const chalk = require('chalk')

function prettyFactory (opts) {
if (!opts) {
Expand Down Expand Up @@ -710,7 +711,7 @@ test('basic prettifier tests', (t) => {
const log = pino({}, new Writable({
write (chunk, enc, cb) {
const formatted = pretty(chunk.toString())
t.is(formatted, `[${epoch}] INFO (${pid} on ${hostname}): message {"extra":{"foo":"bar","number":42},"upper":"FOOBAR"}\n`)
t.is(formatted, `[${epoch}] INFO (${pid} on ${hostname}): message ${chalk.gray('{"extra":{"foo":"bar","number":42},"upper":"FOOBAR"}')}\n`)

cb()
}
Expand Down
3 changes: 2 additions & 1 deletion test/error-objects.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const Writable = require('stream').Writable
const os = require('os')
const test = require('tap').test
const pino = require('pino')
const chalk = require('chalk')
const serializers = pino.stdSerializers
const _prettyFactory = require('../')

Expand Down Expand Up @@ -133,7 +134,7 @@ test('error like objects tests', (t) => {
const formatted = pretty(chunk.toString())
const lines = formatted.split('\n')
t.is(lines.length, expected.length + 5)
t.is(lines[0], `[${epoch}] INFO (${pid} on ${hostname}): {"extra":{"a":1,"b":2}}`)
t.is(lines[0], `[${epoch}] INFO (${pid} on ${hostname}): ${chalk.gray('{"extra":{"a":1,"b":2}}')}`)
t.match(lines[1], /\s{4}err: {/)
t.match(lines[2], /\s{6}"type": "Error",/)
t.match(lines[3], /\s{6}"message": "hello world",/)
Expand Down