diff --git a/lib/constants.js b/lib/constants.js index 5c516a89..4882331d 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -15,8 +15,8 @@ module.exports = { default: 'USERLVL', 60: 'FATAL', 50: 'ERROR', - 40: 'WARN ', - 30: 'INFO ', + 40: 'WARN', + 30: 'INFO', 20: 'DEBUG', 10: 'TRACE' }, diff --git a/lib/utils.js b/lib/utils.js index 16e8c858..1adeb2bd 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -178,7 +178,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' } /** diff --git a/test/basic.test.js b/test/basic.test.js index 9299867a..23a0ec48 100644 --- a/test/basic.test.js +++ b/test/basic.test.js @@ -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() } @@ -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() } @@ -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() } @@ -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() } @@ -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() } @@ -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() } @@ -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() } @@ -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() } @@ -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() } @@ -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() } })) @@ -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: { @@ -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: { @@ -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: { @@ -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() } })) @@ -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() } })) @@ -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() } @@ -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() } @@ -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) { @@ -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) => { @@ -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() } @@ -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) => { @@ -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) => { @@ -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() } @@ -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) => { @@ -656,7 +656,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() } @@ -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) => { @@ -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() } })) diff --git a/test/cli-rc.test.js b/test/cli-rc.test.js index 09de5924..166a128f 100644 --- a/test/cli-rc.test.js +++ b/test/cli-rc.test.js @@ -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(() => { @@ -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(() => { @@ -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(() => { @@ -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()) @@ -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()) @@ -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(() => { @@ -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(() => { diff --git a/test/cli.test.js b/test/cli.test.js index 527e30a0..72cf71e8 100644 --- a/test/cli.test.js +++ b/test/cli.test.js @@ -15,7 +15,7 @@ test('cli', (t) => { const child = spawn(process.argv[0], [bin], { env }) child.on('error', t.threw) child.stdout.on('data', (data) => { - t.is(data.toString(), `[${epoch}] INFO (42 on foo): hello world\n`) + t.is(data.toString(), `[${epoch}] INFO\t (42 on foo): hello world\n`) }) child.stdin.write(logLine) t.tearDown(() => child.kill()) @@ -27,7 +27,7 @@ test('cli', (t) => { const child = spawn(process.argv[0], [bin, '-l'], { env }) child.on('error', t.threw) child.stdout.on('data', (data) => { - t.is(data.toString(), `INFO [${epoch}] (42 on foo): hello world\n`) + t.is(data.toString(), `INFO\t [${epoch}] (42 on foo): hello world\n`) }) child.stdin.write(logLine) t.tearDown(() => child.kill()) @@ -39,7 +39,7 @@ test('cli', (t) => { const child = spawn(process.argv[0], [bin, '-t'], { env }) 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()) @@ -51,7 +51,7 @@ test('cli', (t) => { const child = spawn(process.argv[0], [bin, '-s', 'msg == `hello world`'], { env }) child.on('error', t.threw) child.stdout.on('data', (data) => { - t.is(data.toString(), `[${epoch}] INFO (42 on foo): hello world\n`) + t.is(data.toString(), `[${epoch}] INFO\t (42 on foo): hello world\n`) }) child.stdin.write(logLine) t.tearDown(() => child.kill()) @@ -63,7 +63,7 @@ test('cli', (t) => { const child = spawn(process.argv[0], [bin, '-s', 'msg == `hello world`'], { env }) child.on('error', t.threw) child.stdout.on('data', (data) => { - t.is(data.toString(), `[${epoch}] INFO (42 on foo): hello world\n`) + t.is(data.toString(), `[${epoch}] INFO\t (42 on foo): hello world\n`) }) child.stdin.write(logLine.replace('hello world', 'hello universe')) child.stdin.write(logLine) @@ -76,7 +76,7 @@ test('cli', (t) => { const child = spawn(process.argv[0], [bin, '-i', 'pid,hostname'], { env }) child.on('error', t.threw) child.stdout.on('data', (data) => { - t.is(data.toString(), '[1522431328992] INFO : hello world\n') + t.is(data.toString(), '[1522431328992] INFO\t: hello world\n') }) child.stdin.write(logLine) t.tearDown(() => child.kill()) @@ -106,7 +106,7 @@ test('cli', (t) => { 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') + t.is(data.toString(), '[1522431328992] INFO\t: hello world\n') }) const logLine = '{"level":30,"@timestamp":1522431328992,"msg":"hello world"}\n' child.stdin.write(logLine) diff --git a/test/error-objects.test.js b/test/error-objects.test.js index a1154227..1bff9023 100644 --- a/test/error-objects.test.js +++ b/test/error-objects.test.js @@ -47,7 +47,7 @@ test('error like objects tests', (t) => { const formatted = pretty(chunk.toString()) const lines = formatted.split('\n') t.is(lines.length, expected.length + 1) - t.is(lines[0], `[${epoch}] INFO (${pid} on ${hostname}): hello world`) + t.is(lines[0], `[${epoch}] INFO\t (${pid} on ${hostname}): hello world`) cb() } })) @@ -98,7 +98,7 @@ test('error like objects tests', (t) => { const formatted = pretty(chunk.toString()) const lines = formatted.split('\n') t.is(lines.length, expected.length + 6) - t.is(lines[0], `[${epoch}] INFO (${pid} on ${hostname}):`) + t.is(lines[0], `[${epoch}] INFO\t (${pid} on ${hostname}):`) t.match(lines[1], /\s{4}err: {/) t.match(lines[2], /\s{6}"type": "Error",/) t.match(lines[3], /\s{6}"message": "hello world",/) @@ -129,7 +129,7 @@ test('error like objects tests', (t) => { const formatted = pretty(chunk.toString()) const lines = formatted.split('\n') t.is(lines.length, expected.length + 6) - t.is(lines[0], `[${epoch}] INFO (${pid} on ${hostname}):`) + t.is(lines[0], `[${epoch}] INFO\t (${pid} on ${hostname}):`) t.match(lines[1], /\s{4}err: {$/) t.match(lines[2], /\s{6}"type": "Error",$/) t.match(lines[3], /\s{6}"message": "hello world",$/) @@ -159,7 +159,7 @@ test('error like objects tests', (t) => { const formatted = pretty(chunk.toString()) const lines = formatted.split('\n') t.is(lines.length, expected.length + 7) - t.is(lines[0], `[${epoch}] INFO (${pid} on ${hostname}):`) + t.is(lines[0], `[${epoch}] INFO\t (${pid} on ${hostname}):`) t.match(lines[1], /\s{4}err: {/) t.match(lines[2], /\s{6}"type": "Error",/) t.match(lines[3], /\s{6}"message": "hello world",/) diff --git a/test/lib/colors.test.js b/test/lib/colors.test.js index 6da351ba..42674be3 100644 --- a/test/lib/colors.test.js +++ b/test/lib/colors.test.js @@ -12,10 +12,10 @@ test('returns default colorizer', async t => { t.is(colorized, 'DEBUG') colorized = colorizer(30) - t.is(colorized, 'INFO ') + t.is(colorized, 'INFO') colorized = colorizer(40) - t.is(colorized, 'WARN ') + t.is(colorized, 'WARN') colorized = colorizer(50) t.is(colorized, 'ERROR') @@ -27,7 +27,7 @@ test('returns default colorizer', async t => { t.is(colorized, 'USERLVL') colorized = colorizer('info') - t.is(colorized, 'INFO ') + t.is(colorized, 'INFO') colorized = colorizer('use-default') t.is(colorized, 'USERLVL') @@ -45,10 +45,10 @@ test('returns colorizing colorizer', async t => { t.is(colorized, '\u001B[34mDEBUG\u001B[39m') colorized = colorizer(30) - t.is(colorized, '\u001B[32mINFO \u001B[39m') + t.is(colorized, '\u001B[32mINFO\u001B[39m') colorized = colorizer(40) - t.is(colorized, '\u001B[33mWARN \u001B[39m') + t.is(colorized, '\u001B[33mWARN\u001B[39m') colorized = colorizer(50) t.is(colorized, '\u001B[31mERROR\u001B[39m') @@ -60,7 +60,7 @@ test('returns colorizing colorizer', async t => { t.is(colorized, '\u001B[37mUSERLVL\u001B[39m') colorized = colorizer('info') - t.is(colorized, '\u001B[32mINFO \u001B[39m') + t.is(colorized, '\u001B[32mINFO\u001B[39m') colorized = colorizer('use-default') t.is(colorized, '\u001B[37mUSERLVL\u001B[39m') diff --git a/test/lib/utils.public.test.js b/test/lib/utils.public.test.js index d12f8ed8..a1b17a46 100644 --- a/test/lib/utils.public.test.js +++ b/test/lib/utils.public.test.js @@ -41,7 +41,7 @@ tap.test('prettifyLevel', t => { level: 30 } const colorized = prettifyLevel({ log }) - t.is(colorized, 'INFO ') + t.is(colorized, 'INFO\t') }) t.test('returns colorized value for color colorizer', async t => { @@ -50,7 +50,7 @@ tap.test('prettifyLevel', t => { } const colorizer = getColorizer(true) const colorized = prettifyLevel({ log, colorizer }) - t.is(colorized, '\u001B[32mINFO \u001B[39m') + t.is(colorized, '\u001B[32mINFO\u001B[39m\t') }) t.end()