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

Revert "Prettify Time Before Filtering (#117)" #119

Merged
merged 2 commits into from
Jul 14, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ module.exports = function prettyFactory (options) {
}

const prettifiedMessage = prettifyMessage({ log, messageKey, colorizer, messageFormat })
const prettifiedTime = prettifyTime({ log, translateFormat: opts.translateTime, timestampKey })

if (ignoreKeys) {
log = Object.keys(log)
Expand All @@ -87,6 +86,7 @@ module.exports = function prettyFactory (options) {

const prettifiedLevel = prettifyLevel({ log, colorizer, levelKey })
const prettifiedMetadata = prettifyMetadata({ log })
const prettifiedTime = prettifyTime({ log, translateFormat: opts.translateTime, timestampKey })

let line = ''
if (opts.levelFirst && prettifiedLevel) {
Expand Down
21 changes: 7 additions & 14 deletions test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,13 @@ test('basic prettifier tests', (t) => {
t.is(arst, `[${epoch}] INFO (on ${hostname}): hello world\n`)
})

t.test('ignores time', (t) => {
t.plan(1)
const pretty = prettyFactory({ ignore: 'time' })
const arst = pretty(`{"msg":"hello world", "pid":"${pid}", "hostname":"${hostname}", "time":${epoch}, "level":30, "v":1}`)
t.is(arst, `INFO (${pid} on ${hostname}): hello world\n`)
})

t.test('prettifies trace caller', (t) => {
t.plan(1)
const traceCaller = (instance) => {
Expand Down Expand Up @@ -643,19 +650,5 @@ 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 @timestamp: ${epoch}\n`)
})

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

t.end()
})
26 changes: 0 additions & 26 deletions test/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,31 +100,5 @@ 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 @timestamp: 1522431328992\n')
})
const logLine = '{"level":30,"@timestamp":1522431328992,"msg":"hello world"}\n'
child.stdin.write(logLine)
t.tearDown(() => child.kill())
})

t.test('uses an ignored timestampKey', (t) => {
t.plan(1)
const env = { TERM: 'dumb' }
const child = spawn(process.argv[0], [bin, '--timestampKey', '@timestamp', '--ignore', '@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()
})