issue #4: add 'pid' automatic log record field

This commit is contained in:
Trent Mick 2012-02-09 21:07:01 -08:00
parent e8581c52c7
commit c12a90a511
5 changed files with 35 additions and 28 deletions

View file

@ -1,8 +1,9 @@
# bunyan Changelog
## bunyan 0.5.4 (not yet released)
## bunyan 0.6.0 (not yet released)
- Add 'pid' automatic log record field.
(nothing yet)
## bunyan 0.5.3

View file

@ -256,13 +256,14 @@ incorrect signature) is always a bug in Bunyan.**
A typical Bunyan log record looks like this:
{"name":"myserver","hostname":"banana.local","req":{"method":"GET","url":"/path?q=1#anchor","headers":{"x-hi":"Mom","connection":"close"}},"level":3,"msg":"start request","time":"2012-02-03T19:02:46.178Z","v":0}
{"name":"myserver","hostname":"banana.local","pid":123,"req":{"method":"GET","url":"/path?q=1#anchor","headers":{"x-hi":"Mom","connection":"close"}},"level":3,"msg":"start request","time":"2012-02-03T19:02:46.178Z","v":0}
Pretty-printed:
{
"name": "myserver",
"hostname": "banana.local",
"pid": 123,
"req": {
"method": "GET",
"url": "/path?q=1#anchor",
@ -296,6 +297,7 @@ Core fields:
- `hostname`: Required. String. Provided or determined at Logger creation.
You can specify your hostname at Logger creation or it will be retrieved
vi `os.hostname()`.
- `pid`: Required. Integer. Filled in automatically at Logger creation.
- `time`: Required. String. Added by Bunion. Can be overriden.
The date and time of the event in [ISO 8601
Extended Format](http://en.wikipedia.org/wiki/ISO_8601) format and in UTC,
@ -446,5 +448,3 @@ See "TODO.md", but basically:
- Syslog support.
- Some speed comparisons with others to get a feel for Bunyan's speed.

View file

@ -5,7 +5,7 @@
// See <https://github.com/trentm/node-bunyan>.
//
var VERSION = "0.5.4";
var VERSION = "0.6.0";
var util = require('util');
var pathlib = require('path');
@ -264,7 +264,7 @@ function handleLogLine(line, opts) {
switch (opts.outputMode) {
case OM_PAUL:
// [time] LEVEL: name[/component] on hostname (src): msg* (extras...)
// [time] LEVEL: name[/component]/pid on hostname (src): msg* (extras...)
// msg*
// --
// long and multi-line extras
@ -286,6 +286,9 @@ function handleLogLine(line, opts) {
}
delete rec.component;
nameStr += '/' + rec.pid;
delete rec.pid;
var level = (upperNameFromLevel[rec.level] || "<level " + rec.level + ">");
delete rec.level;

View file

@ -4,7 +4,7 @@
* The bunyan logging library for node.js.
*/
var VERSION = "0.5.4";
var VERSION = "0.6.0";
// Bunyan log format version. This becomes the 'v' field on all log records.
// `0` is until I release a version "1.0.0" of node-bunyan. Thereafter,
@ -384,6 +384,9 @@ function Logger(options, _childOptions, _childSimple) {
if (!fields.hostname) {
fields.hostname = os.hostname();
}
if (!fields.pid) {
fields.pid = process.pid;
}
Object.keys(fields).forEach(function (k) {
self.fields[k] = fields[k];
});

View file

@ -1,6 +1,6 @@
{
"name": "bunyan",
"version": "0.5.4",
"version": "0.6.0",
"description": "a JSON Logger library for node.js servers",
"main": "./lib/bunyan.js",
"bin": {