Skip to content

Commit

Permalink
Cache the pid and hostname globally
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina committed Jun 19, 2016
1 parent f3f27ae commit 0aabe9c
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions pino.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var once = require('once')
var noop = require('./noop')
var pid = process.pid
var hostname = os.hostname()
var baseLog = flatstr('{"pid":' + pid + ',"hostname":"' + hostname + '",')

var LOG_VERSION = 1

Expand Down Expand Up @@ -61,7 +62,7 @@ function pino (opts, stream) {
level = 'silent'
}

var logger = new Pino(level, stream, serializers, stringify, end, name, hostname, slowtime, '', cache, formatOpts)
var logger = new Pino(level, stream, serializers, stringify, end, name, slowtime, '', cache, formatOpts)
if (cache) {
onExit(function (code, evt) {
if (cache.buf) {
Expand Down Expand Up @@ -95,13 +96,12 @@ Object.defineProperty(pino, 'levels', {
enumerable: true
})

function Pino (level, stream, serializers, stringify, end, name, hostname, slowtime, chindings, cache, formatOpts) {
function Pino (level, stream, serializers, stringify, end, name, slowtime, chindings, cache, formatOpts) {
this.stream = stream
this.serializers = serializers
this.stringify = stringify
this.end = end
this.name = name
this.hostname = hostname
this.slowtime = slowtime
this.chindings = chindings
this.cache = cache
Expand Down Expand Up @@ -193,8 +193,7 @@ Pino.prototype.asJson = function asJson (obj, msg, num) {
// returns string json with final brace omitted
// the final brace is added by asJson
Pino.prototype.message = function message (level, msg) {
return '{"pid":' + pid + ',' +
(this.hostname === undefined ? '' : '"hostname":"' + this.hostname + '",') +
return baseLog +
(this.name === undefined ? '' : '"name":"' + this.name + '",') +
'"level":' + level + ',' +
(msg === undefined ? '' : '"msg":"' + (msg && msg.toString()) + '",') +
Expand Down Expand Up @@ -225,7 +224,6 @@ Pino.prototype.child = function child (bindings) {
this.stringify,
this.end,
this.name,
this.hostname,
this.slowtime,
data,
this.cache,
Expand Down

0 comments on commit 0aabe9c

Please sign in to comment.