Skip to content

Commit

Permalink
Avoid slicing.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina committed Mar 7, 2016
1 parent 9573b86 commit 7cec08e
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions pino.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,8 @@ function pino (opts, stream) {
var data = message(num, msg)
var value
if (obj) {
data = data.slice(0, data.length - 1)

if (obj instanceof Error) {
data += ',"type":"Error","stack":' + stringify(obj.stack) + '}'
data += ',"type":"Error","stack":' + stringify(obj.stack)
} else {
for (var key in obj) {
value = obj[key]
Expand All @@ -113,20 +111,21 @@ function pino (opts, stream) {
data += ',"' + key + '":' + stringify(value)
}
}
data += '}'
}
}
return data + '\n'
return data + '}\n'
}

// returns string json with final brace omitted
// the final brace is added by asJson
function message (level, msg) {
return '{"pid":' + pid + ',' +
(typeof hostname === 'undefined' ? '' : '"hostname":"' + hostname + '",') +
(typeof name === 'undefined' ? '' : '"name":"' + name + '",') +
'"level":' + level + ',' +
(typeof msg === 'undefined' ? '' : '"msg":"' + (msg && msg.toString()) + '",') +
'"time":"' + (new Date()).toISOString() + '",' +
'"v":' + 0 + '}'
'"v":' + 0
}
}

Expand Down

0 comments on commit 7cec08e

Please sign in to comment.