Skip to content

Commit

Permalink
Merge branch 'master' into issue-167
Browse files Browse the repository at this point in the history
  • Loading branch information
jsumners committed Jan 17, 2017
2 parents 7fcf153 + 9baa06e commit f2b0edf
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "pino",
"version": "3.1.1",
"version": "3.1.2",
"description": "super fast, all natural json logger",
"main": "pino.js",
"browser": "./browser.js",
Expand Down
2 changes: 1 addition & 1 deletion pino.js
Expand Up @@ -240,7 +240,7 @@ Pino.prototype.asJson = function asJson (obj, msg, num) {
// to catch both null and undefined
/* eslint-disable eqeqeq */
if (msg != undefined) {
data += ',"msg":' + JSON.stringify(msg)
data += ',"msg":' + JSON.stringify('' + msg)
}
var value
if (obj) {
Expand Down
8 changes: 7 additions & 1 deletion pretty.js
Expand Up @@ -7,6 +7,7 @@ var Parse = require('fast-json-parse')
var chalk = require('chalk')

var levels = {
default: 'USERLVL',
60: 'FATAL',
50: 'ERROR',
40: 'WARN',
Expand Down Expand Up @@ -70,6 +71,7 @@ function pretty (opts) {
})

levelColors = {
default: ctx.white,
60: ctx.bgRed,
50: ctx.red,
40: ctx.yellow,
Expand Down Expand Up @@ -128,7 +130,11 @@ function pretty (opts) {
}

function asColoredLevel (value) {
return levelColors[value.level](levels[value.level])
if (levelColors.hasOwnProperty(value.level)) {
return levelColors[value.level](levels[value.level])
} else {
return levelColors.default(levels.default)
}
}
}

Expand Down
35 changes: 35 additions & 0 deletions test/basic.test.js
Expand Up @@ -342,3 +342,38 @@ test('correctly support node v4+ stderr', function (t) {

instance.fatal('a message')
})

test('normalize number to string', function (t) {
var instance = pino(sink(function (chunk, enc, cb) {
delete chunk.time
t.deepEqual(chunk, {
pid: pid,
hostname: hostname,
level: 30,
msg: '1',
v: 1
})
t.end()
cb()
}))

instance.info(1)
})

test('normalize number to string with an object', function (t) {
var instance = pino(sink(function (chunk, enc, cb) {
delete chunk.time
t.deepEqual(chunk, {
pid: pid,
hostname: hostname,
level: 30,
msg: '1',
answer: 42,
v: 1
})
t.end()
cb()
}))

instance.info({ answer: 42 }, 1)
})
14 changes: 14 additions & 0 deletions test/pretty.test.js
Expand Up @@ -172,3 +172,17 @@ test('handles `true` input', function (t) {
pretty.write('true')
pretty.end()
})

test('accept customLogLevvel', function (t) {
t.plan(1)
var pretty = pino.pretty()

pretty.pipe(split(function (line) {
t.ok(line.indexOf('USERLVL') > 0, 'include custom level')
return line
}))

var instance = pino({level: 'testCustom', levelVal: 35}, pretty)

instance.testCustom('test message')
})

0 comments on commit f2b0edf

Please sign in to comment.