Skip to content

Commit

Permalink
Use tab to align output of all levels (pinojs#135)
Browse files Browse the repository at this point in the history
Use tab to align output of all levels instead of a single space to align only INFO/WARN levels
  • Loading branch information
dublx authored Oct 5, 2020
1 parent 820008c commit ec09288
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 58 deletions.
4 changes: 2 additions & 2 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ module.exports = {
default: 'USERLVL',
60: 'FATAL',
50: 'ERROR',
40: 'WARN ',
30: 'INFO ',
40: 'WARN',
30: 'INFO',
20: 'DEBUG',
10: 'TRACE'
},
Expand Down
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ function prettifyErrorLog ({
*/
function prettifyLevel ({ log, colorizer = defaultColorizer, levelKey = LEVEL_KEY }) {
if (levelKey in log === false) return undefined
return colorizer(log[levelKey])
return colorizer(log[levelKey]) + '\t'
}

/**
Expand Down
58 changes: 29 additions & 29 deletions test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ test('basic prettifier tests', (t) => {
const formatted = pretty(chunk.toString())
t.is(
formatted,
`[${epoch}] INFO (${pid} on ${hostname}): foo\n`
`[${epoch}] INFO\t (${pid} on ${hostname}): foo\n`
)
cb()
}
Expand All @@ -65,7 +65,7 @@ test('basic prettifier tests', (t) => {
const formatted = pretty(chunk.toString())
t.is(
formatted,
`[${epoch}] \u001B[32mINFO \u001B[39m (${pid} on ${hostname}): \u001B[36mfoo\u001B[39m\n`
`[${epoch}] \u001B[32mINFO\u001B[39m\t (${pid} on ${hostname}): \u001B[36mfoo\u001B[39m\n`
)
cb()
}
Expand All @@ -81,7 +81,7 @@ test('basic prettifier tests', (t) => {
const formatted = pretty(chunk.toString())
t.is(
formatted,
`INFO [${epoch}] (${pid} on ${hostname}): foo\n`
`INFO\t [${epoch}] (${pid} on ${hostname}): foo\n`
)
cb()
}
Expand All @@ -97,7 +97,7 @@ test('basic prettifier tests', (t) => {
const formatted = pretty(chunk.toString())
t.is(
formatted,
`[${epoch}] INFO (${pid} on ${hostname}): baz\n`
`[${epoch}] INFO\t (${pid} on ${hostname}): baz\n`
)
cb()
}
Expand All @@ -113,7 +113,7 @@ test('basic prettifier tests', (t) => {
const formatted = pretty(chunk.toString())
t.is(
formatted,
`[${epoch}] WARN (${pid} on ${hostname}): foo\n`
`[${epoch}] WARN\t (${pid} on ${hostname}): foo\n`
)
cb()
}
Expand All @@ -129,7 +129,7 @@ test('basic prettifier tests', (t) => {
const formatted = pretty(chunk.toString())
t.is(
formatted,
`[2018-03-30 17:35:28.992 +0000] INFO (${pid} on ${hostname}): foo\n`
`[2018-03-30 17:35:28.992 +0000] INFO\t (${pid} on ${hostname}): foo\n`
)
cb()
}
Expand All @@ -147,7 +147,7 @@ test('basic prettifier tests', (t) => {
const offset = dateformat(epoch, 'UTC:' + 'o')
t.is(
formatted,
`[${utcHour}:35:28 ${offset}] INFO (${pid} on ${hostname}): foo\n`
`[${utcHour}:35:28 ${offset}] INFO\t (${pid} on ${hostname}): foo\n`
)
cb()
}
Expand All @@ -166,7 +166,7 @@ test('basic prettifier tests', (t) => {
const offset = dateformat(epoch, 'o')
t.is(
formatted,
`[${localDate} ${localHour}:35:28.992 ${offset}] INFO (${pid} on ${hostname}): foo\n`
`[${localDate} ${localHour}:35:28.992 ${offset}] INFO\t (${pid} on ${hostname}): foo\n`
)
cb()
}
Expand All @@ -187,7 +187,7 @@ test('basic prettifier tests', (t) => {
const offset = dateformat(epoch, 'o')
t.is(
formatted,
`[${localDate} ${localHour}:35:28 ${offset}] INFO (${pid} on ${hostname}): foo\n`
`[${localDate} ${localHour}:35:28 ${offset}] INFO\t (${pid} on ${hostname}): foo\n`
)
cb()
}
Expand All @@ -209,7 +209,7 @@ test('basic prettifier tests', (t) => {
const log = pino({ base: null }, new Writable({
write (chunk, enc, cb) {
const formatted = pretty(chunk.toString())
t.match(formatted, /\[.*\] INFO : hello world/)
t.match(formatted, /\[.*\] INFO\t: hello world/)
cb()
}
}))
Expand All @@ -221,7 +221,7 @@ test('basic prettifier tests', (t) => {
const pretty = prettyFactory()
const name = 'test'
const msg = 'hello world'
const regex = new RegExp('\\[.*\\] INFO \\(' + name + ' on ' + hostname + '\\): ' + msg)
const regex = new RegExp('\\[.*\\] INFO\t \\(' + name + ' on ' + hostname + '\\): ' + msg)

const opts = {
base: {
Expand All @@ -245,7 +245,7 @@ test('basic prettifier tests', (t) => {
const pretty = prettyFactory()
const name = 'test'
const msg = 'hello world'
const regex = new RegExp('\\[.*\\] INFO \\(' + name + '/' + pid + '\\): ' + msg)
const regex = new RegExp('\\[.*\\] INFO\t \\(' + name + '/' + pid + '\\): ' + msg)

const opts = {
base: {
Expand All @@ -268,7 +268,7 @@ test('basic prettifier tests', (t) => {
t.plan(1)
const pretty = prettyFactory()
const msg = 'hello world'
const regex = new RegExp('\\[.*\\] INFO \\(' + process.pid + ' on ' + hostname + '\\): ' + msg)
const regex = new RegExp('\\[.*\\] INFO\t \\(' + process.pid + ' on ' + hostname + '\\): ' + msg)

const opts = {
base: {
Expand All @@ -293,7 +293,7 @@ test('basic prettifier tests', (t) => {
const log = pino({ timestamp: null }, new Writable({
write (chunk, enc, cb) {
const formatted = pretty(chunk.toString())
t.is(formatted, `INFO (${pid} on ${hostname}): hello world\n`)
t.is(formatted, `INFO\t (${pid} on ${hostname}): hello world\n`)
cb()
}
}))
Expand Down Expand Up @@ -344,7 +344,7 @@ test('basic prettifier tests', (t) => {
const log = pino({ name: 'matteo' }, new Writable({
write (chunk, enc, cb) {
const formatted = pretty(chunk.toString())
t.is(formatted, `[${epoch}] INFO (matteo/${pid} on ${hostname}): hello world\n`)
t.is(formatted, `[${epoch}] INFO\t (matteo/${pid} on ${hostname}): hello world\n`)
cb()
}
}))
Expand Down Expand Up @@ -411,7 +411,7 @@ test('basic prettifier tests', (t) => {
write (chunk, enc, cb) {
t.is(
chunk.toString(),
`[${epoch}] INFO (${pid} on ${hostname}): foo\n`
`[${epoch}] INFO\t (${pid} on ${hostname}): foo\n`
)
cb()
}
Expand All @@ -431,7 +431,7 @@ test('basic prettifier tests', (t) => {
write (formatted, enc, cb) {
t.is(
formatted,
`INFO [${epoch}] (${pid} on ${hostname}): foo\n`
`INFO\t [${epoch}] (${pid} on ${hostname}): foo\n`
)
cb()
}
Expand All @@ -451,7 +451,7 @@ test('basic prettifier tests', (t) => {
const expected = [
undefined,
undefined,
`[${epoch}] INFO (${pid} on ${hostname}): foo\n foo: {\n "bar": true\n }\n`
`[${epoch}] INFO\t (${pid} on ${hostname}): foo\n foo: {\n "bar": true\n }\n`
]
const log = pino({}, new Writable({
write (chunk, enc, cb) {
Expand All @@ -475,7 +475,7 @@ test('basic prettifier tests', (t) => {
let formatted = pretty(`{"msg":"nope", "time":${epoch}, "level":30}`)
t.is(formatted, undefined)
formatted = pretty(`{"msg":"hello world", "time":${epoch}, "level":30}`)
t.is(formatted, `[${epoch}] INFO : hello world\n`)
t.is(formatted, `[${epoch}] INFO\t: hello world\n`)
})

t.test('formats a line with an undefined field', (t) => {
Expand All @@ -489,7 +489,7 @@ test('basic prettifier tests', (t) => {
const formatted = pretty(obj)
t.is(
formatted,
`[${epoch}] INFO (${pid} on ${hostname}): foo\n`
`[${epoch}] INFO\t (${pid} on ${hostname}): foo\n`
)
cb()
}
Expand Down Expand Up @@ -560,7 +560,7 @@ test('basic prettifier tests', (t) => {
}
})
const arst = pretty('{"msg":"hello world", "foo": "bar", "cow": "moo", "level":30}')
t.is(arst, 'INFO : hello world\n foo: bar_baz\n multiline\n cow: MOO\n')
t.is(arst, 'INFO\t: hello world\n foo: bar_baz\n multiline\n cow: MOO\n')
})

t.test('does not prettify custom key that does not exists', (t) => {
Expand All @@ -572,7 +572,7 @@ test('basic prettifier tests', (t) => {
}
})
const arst = pretty('{"msg":"hello world", "foo": "bar", "level":30}')
t.is(arst, 'INFO : hello world\n foo: bar_baz\n')
t.is(arst, 'INFO\t: hello world\n foo: bar_baz\n')
})

t.test('prettifies object with some undefined values', (t) => {
Expand All @@ -581,7 +581,7 @@ test('basic prettifier tests', (t) => {
write (chunk, _, cb) {
t.is(
chunk + '',
`[${epoch}] INFO (${pid} on ${hostname}):\n a: {\n "b": "c"\n }\n n: null\n`
`[${epoch}] INFO\t (${pid} on ${hostname}):\n a: {\n "b": "c"\n }\n n: null\n`
)
cb()
}
Expand All @@ -604,21 +604,21 @@ test('basic prettifier tests', (t) => {
t.plan(1)
const pretty = prettyFactory({ ignore: 'pid,hostname' })
const arst = pretty(`{"msg":"hello world", "pid":"${pid}", "hostname":"${hostname}", "time":${epoch}, "level":30}`)
t.is(arst, `[${epoch}] INFO : hello world\n`)
t.is(arst, `[${epoch}] INFO\t: hello world\n`)
})

t.test('ignores a single key', (t) => {
t.plan(1)
const pretty = prettyFactory({ ignore: 'pid' })
const arst = pretty(`{"msg":"hello world", "pid":"${pid}", "hostname":"${hostname}", "time":${epoch}, "level":30}`)
t.is(arst, `[${epoch}] INFO (on ${hostname}): hello world\n`)
t.is(arst, `[${epoch}] INFO\t (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}`)
t.is(arst, `INFO (${pid} on ${hostname}): hello world\n`)
t.is(arst, `INFO\t (${pid} on ${hostname}): hello world\n`)
})

t.test('ignores time and level', (t) => {
Expand Down Expand Up @@ -656,7 +656,7 @@ test('basic prettifier tests', (t) => {
const formatted = pretty(chunk.toString())
t.is(
formatted,
`[${epoch}] INFO (${pid} on ${hostname}) </tmp/script.js>: foo\n`
`[${epoch}] INFO\t (${pid} on ${hostname}) </tmp/script.js>: foo\n`
)
cb()
}
Expand All @@ -668,7 +668,7 @@ test('basic prettifier tests', (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.is(arst, `[${epoch}] INFO\t: hello world\n`)
})

t.test('keeps "v" key in log', (t) => {
Expand All @@ -677,7 +677,7 @@ test('basic prettifier tests', (t) => {
const log = pino({}, new Writable({
write (chunk, enc, cb) {
const formatted = pretty(chunk.toString())
t.is(formatted, `INFO (${pid} on ${hostname}):\n v: 1\n`)
t.is(formatted, `INFO\t (${pid} on ${hostname}):\n v: 1\n`)
cb()
}
}))
Expand Down
14 changes: 7 additions & 7 deletions test/cli-rc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ test('cli', (t) => {
// Validate that the time has been translated
child.on('error', t.threw)
child.stdout.on('data', (data) => {
t.is(data.toString(), '[2018-03-30 17:35:28.992 +0000] INFO (42 on foo): hello world\n')
t.is(data.toString(), '[2018-03-30 17:35:28.992 +0000] INFO\t (42 on foo): hello world\n')
})
child.stdin.write(logLine)
t.tearDown(() => {
Expand All @@ -45,7 +45,7 @@ test('cli', (t) => {
// Validate that the time has been translated
child.on('error', t.threw)
child.stdout.on('data', (data) => {
t.is(data.toString(), '[2018-03-30 17:35:28.992 +0000] INFO (42 on foo): hello world\n')
t.is(data.toString(), '[2018-03-30 17:35:28.992 +0000] INFO\t (42 on foo): hello world\n')
})
child.stdin.write(logLine)
t.tearDown(() => {
Expand All @@ -64,7 +64,7 @@ test('cli', (t) => {
// Validate that the time has been translated
child.on('error', t.threw)
child.stdout.on('data', (data) => {
t.is(data.toString(), '[2018-03-30 17:35:28.992 +0000] INFO (42 on foo): hello world\n')
t.is(data.toString(), '[2018-03-30 17:35:28.992 +0000] INFO\t (42 on foo): hello world\n')
})
child.stdin.write(logLine)
t.tearDown(() => {
Expand All @@ -83,7 +83,7 @@ test('cli', (t) => {
// Validate that the time has been translated
child.on('error', t.threw)
child.stdout.on('data', (data) => {
t.is(data.toString(), '[2018-03-30 17:35:28.992 +0000] INFO (42 on foo): hello world\n')
t.is(data.toString(), '[2018-03-30 17:35:28.992 +0000] INFO\t (42 on foo): hello world\n')
})
child.stdin.write(logLine)
t.tearDown(() => child.kill())
Expand All @@ -99,7 +99,7 @@ test('cli', (t) => {
// Validate that the time has been translated
child.on('error', t.threw)
child.stdout.on('data', (data) => {
t.is(data.toString(), '[2018-03-30 17:35:28.992 +0000] INFO (42 on foo): hello world\n')
t.is(data.toString(), '[2018-03-30 17:35:28.992 +0000] INFO\t (42 on foo): hello world\n')
})
child.stdin.write(logLine)
t.tearDown(() => child.kill())
Expand All @@ -121,7 +121,7 @@ test('cli', (t) => {
// Validate that the time has been translated and correct message key has been used
child.on('error', t.threw)
child.stdout.on('data', (data) => {
t.is(data.toString(), '[2018-03-30 17:35:28.992 +0000] INFO (42 on foo): hello world\n')
t.is(data.toString(), '[2018-03-30 17:35:28.992 +0000] INFO\t (42 on foo): hello world\n')
})
child.stdin.write(logLine.replace(/"msg"/, '"new_msg"'))
t.tearDown(() => {
Expand All @@ -145,7 +145,7 @@ test('cli', (t) => {
// Validate that the time has been translated and correct message key has been used
child.on('error', t.threw)
child.stdout.on('data', (data) => {
t.is(data.toString(), '[1594416696006] FATAL: There was an error starting the process.\n QueryError: Error during sql query: syntax error at or near SELECTT\n at /home/me/projects/example/sql.js\n at /home/me/projects/example/index.js\nquerySql: SELECTT * FROM "test" WHERE id = $1;\nqueryArgs: 12\n')
t.is(data.toString(), '[1594416696006] FATAL\t: There was an error starting the process.\n QueryError: Error during sql query: syntax error at or near SELECTT\n at /home/me/projects/example/sql.js\n at /home/me/projects/example/index.js\nquerySql: SELECTT * FROM "test" WHERE id = $1;\nqueryArgs: 12\n')
})
child.stdin.write('{"level":60,"time":1594416696006,"msg":"There was an error starting the process.","type":"Error","stack":"QueryError: Error during sql query: syntax error at or near SELECTT\\n at /home/me/projects/example/sql.js\\n at /home/me/projects/example/index.js","querySql":"SELECTT * FROM \\"test\\" WHERE id = $1;","queryArgs":[12]}\n')
t.tearDown(() => {
Expand Down
Loading

0 comments on commit ec09288

Please sign in to comment.