diff --git a/CHANGES.md b/CHANGES.md index 7d2472c..8acc2ce 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 diff --git a/README.md b/README.md index 06299a3..500f43d 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ be added, including support for custom formats. $ node hi.js | ./bin/bunyan # CLI tool to filter/pretty-print JSON logs. [2012-01-31T00:08:11.387Z] INFO: myapp on banana.local: hi - + $ node hi.js | ./bin/bunyan -o json { "name": "myapp", @@ -69,7 +69,7 @@ be added, including support for custom formats. By default, log output is to stdout (**stream**) and at the "info" level. Explicitly that looks like: - var log = new Logger({name: "myapp", stream: process.stdout, + var log = new Logger({name: "myapp", stream: process.stdout, level: "info"}); That is an abbreviated form for a single stream. **You can defined multiple @@ -101,7 +101,7 @@ same config as its parent, plus include the "component" field. var log = new Logger(...); ... - + function Wuzzle(options) { this.log = options.log; this.log.info("creating a wuzzle") @@ -109,7 +109,7 @@ same config as its parent, plus include the "component" field. Wuzzle.prototype.woos = function () { this.log.warn("This wuzzle is woosey.") } - + var wuzzle = new Wuzzle({log: log.child({component: "wuzzle"})}); wuzzle.woos(); log.info("done with the wuzzle") @@ -225,14 +225,14 @@ The lowercase level names are aliases supported in the API. Here is the API for changing levels in an existing logger: log.level() -> INFO // gets current level (lowest level of all streams) - + log.level(INFO) // set all streams to level INFO log.level("info") // set all streams to level INFO log.levels() -> [DEBUG, INFO] // get array of levels of all streams log.levels(0) -> DEBUG // get level of stream at index 0 log.levels("foo") // get level of stream with name "foo" - + log.levels(0, INFO) // set level of stream 0 to INFO log.levels(0, "info") // can use "info" et al aliases log.levels("foo", WARN) // set stream named "foo" to WARN @@ -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, @@ -317,7 +319,7 @@ Recommended/Best Practice Fields: - `err`: Object. A caught JS exception. Log that thing with `log.info(err)` to get: - + ... "err": { "message": "boom", @@ -340,7 +342,7 @@ Recommended/Best Practice Fields: - `req`: An HTTP server request. Bunyan provides `Logger.stdSerializers.req` to serialize a request with a suggested set of keys. Example: - + { "method": "GET", "url": "/path?q=1#anchor", @@ -353,7 +355,7 @@ Recommended/Best Practice Fields: } - `res`: An HTTP server response. Bunyan provides `Logger.stdSerializers.res` - to serialize a response with a suggested set of keys. Example: + to serialize a response with a suggested set of keys. Example: { "statusCode": 200, @@ -446,5 +448,3 @@ See "TODO.md", but basically: - Syslog support. - Some speed comparisons with others to get a feel for Bunyan's speed. - - diff --git a/bin/bunyan b/bin/bunyan index a5cc210..bf5c381 100755 --- a/bin/bunyan +++ b/bin/bunyan @@ -5,7 +5,7 @@ // See . // -var VERSION = "0.5.4"; +var VERSION = "0.6.0"; var util = require('util'); var pathlib = require('path'); @@ -77,7 +77,7 @@ if (!format) { } return objects.join(' '); } - + var i = 1; var args = arguments; var len = args.length; @@ -164,7 +164,7 @@ function parseArgv(argv) { outputMode: OM_PAUL, jsonIndent: 2 }; - + // Turn '-iH' into '-i -H', except for argument-accepting options. var args = argv.slice(2); // drop ['node', 'scriptname'] var newArgs = []; @@ -231,7 +231,7 @@ function parseArgv(argv) { } parsed.args.push(arg); break; - } + } } //TODO: '--' handling and error on a first arg that looks like an option. @@ -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] || ""); delete rec.level; @@ -299,7 +302,7 @@ function handleLogLine(line, opts) { } } delete rec.src; - + var hostname = rec.hostname; delete rec.hostname; @@ -310,7 +313,7 @@ function handleLogLine(line, opts) { extras.push("req_id=" + rec.req_id); } delete rec.req_id; - + if (rec.latency) { extras.push(rec.latency + "ms"); } @@ -367,7 +370,7 @@ function handleLogLine(line, opts) { } } delete rec.res; - + if (rec.err && rec.err.stack) { details.push(indent(rec.err.stack)) } @@ -482,7 +485,7 @@ function main(argv) { util.puts("bunyan " + getVersion()); return; } - + var leftover = ""; // Left-over partial line from last chunk. var stdin = process.openStdin(); stdin.setEncoding('utf8'); @@ -493,7 +496,7 @@ function main(argv) { leftover += lines[0]; return; } - + if (length > 1) { handleLogLine(leftover + lines[0], opts); } @@ -503,7 +506,7 @@ function main(argv) { handleLogLine(lines[i], opts); } }); - + stdin.on('end', function () { if (leftover) { handleLogLine(leftover, opts); @@ -525,6 +528,6 @@ if (require.main === module) { /* pass */ }; } - + main(process.argv); } diff --git a/lib/bunyan.js b/lib/bunyan.js index 2aa867c..8801ece 100644 --- a/lib/bunyan.js +++ b/lib/bunyan.js @@ -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]; }); diff --git a/package.json b/package.json index 36f064d..5422bfb 100644 --- a/package.json +++ b/package.json @@ -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": {