Skip to content

Commit

Permalink
Skip timestampKey in Prettified Object (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
BenGale authored Jul 15, 2020
1 parent 1f4838d commit efe8c1f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ module.exports = function prettyFactory (options) {
})
line += prettifiedErrorLog
} else {
const skipKeys = [messageKey, levelKey].filter(key => typeof log[key] === 'string')
const skipKeys = [messageKey, levelKey, timestampKey].filter(key => typeof log[key] === 'string' || typeof log[key] === 'number')
const prettifiedObject = prettifyObject({
input: log,
skipKeys,
Expand Down
7 changes: 7 additions & 0 deletions test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -650,5 +650,12 @@ test('basic prettifier tests', (t) => {
log.info('foo')
})

t.test('handles specified timestampKey', (t) => {
t.plan(1)
const pretty = prettyFactory({ timestampKey: '@timestamp' })
const arst = pretty(`{"msg":"hello world", "@timestamp":${epoch}, "level":30}`)
t.is(arst, `[${epoch}] INFO : hello world\n`)
})

t.end()
})
13 changes: 13 additions & 0 deletions test/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,18 @@ test('cli', (t) => {
t.tearDown(() => child.kill())
})

t.test('uses specified timestampKey', (t) => {
t.plan(1)
const env = { TERM: 'dumb' }
const child = spawn(process.argv[0], [bin, '--timestampKey', '@timestamp'], { env })
child.on('error', t.threw)
child.stdout.on('data', (data) => {
t.is(data.toString(), '[1522431328992] INFO : hello world\n')
})
const logLine = '{"level":30,"@timestamp":1522431328992,"msg":"hello world"}\n'
child.stdin.write(logLine)
t.tearDown(() => child.kill())
})

t.end()
})

0 comments on commit efe8c1f

Please sign in to comment.