'long' and 'bunyan' output formats

This commit is contained in:
Trent Mick 2013-03-08 16:32:10 -08:00
parent 4152ea2686
commit 947705ad1e
4 changed files with 46 additions and 14 deletions

View file

@ -8,7 +8,10 @@ Known issues:
## bunyan 0.18.4 (not yet released) ## bunyan 0.18.4 (not yet released)
(nothing yet) - "long" and "bunyan" output formats for the CLI. `bunyan -o long` is the default
format, the same as before, just called "long" now instead of the cheesy "paul"
name. The "bunyan" output format is the same as "json-0", just with a more
convenient name.
## bunyan 0.18.3 ## bunyan 0.18.3

View file

@ -31,17 +31,20 @@ var nodeSpawnSupportsStdio = (
var _DEBUG = false; var _DEBUG = false;
// Output modes. // Output modes.
var OM_PAUL = 1; var OM_LONG = 1;
var OM_JSON = 2; var OM_JSON = 2;
var OM_INSPECT = 3; var OM_INSPECT = 3;
var OM_SIMPLE = 4; var OM_SIMPLE = 4;
var OM_SHORT = 5; var OM_SHORT = 5;
var OM_BUNYAN = 6;
var OM_FROM_NAME = { var OM_FROM_NAME = {
"paul": OM_PAUL, "long": OM_LONG,
"paul": OM_LONG, /* backward compat */
"json": OM_JSON, "json": OM_JSON,
"inspect": OM_INSPECT, "inspect": OM_INSPECT,
"simple": OM_SIMPLE, "simple": OM_SIMPLE,
"short": OM_SHORT "short": OM_SHORT,
"bunyan": OM_BUNYAN
}; };
@ -202,11 +205,12 @@ function printHelp() {
console.log(" --no-color Force no coloring (e.g. terminal doesn't support it)"); console.log(" --no-color Force no coloring (e.g. terminal doesn't support it)");
console.log(" -o, --output MODE"); console.log(" -o, --output MODE");
console.log(" Specify an output mode/format. One of"); console.log(" Specify an output mode/format. One of");
console.log(" paul: (the default) pretty"); console.log(" long: (the default) pretty");
console.log(" json: JSON output, 2-space indent"); console.log(" json: JSON output, 2-space indent");
console.log(" json-N: JSON output, N-space indent, e.g. 'json-4'"); console.log(" json-N: JSON output, N-space indent, e.g. 'json-4'");
console.log(" bunyan: 0 indented JSON, bunyan's native format");
console.log(" inspect: node.js `util.inspect` output"); console.log(" inspect: node.js `util.inspect` output");
console.log(" short: like paul, but more concise"); console.log(" short: like 'long', but more concise");
console.log(" -j shortcut for `-o json`"); console.log(" -j shortcut for `-o json`");
console.log(""); console.log("");
console.log("Log Levels:"); console.log("Log Levels:");
@ -352,7 +356,7 @@ function parseArgv(argv) {
help: false, help: false,
color: null, color: null,
paginate: null, paginate: null,
outputMode: OM_PAUL, outputMode: OM_LONG,
jsonIndent: 2, jsonIndent: 2,
level: null, level: null,
conditions: null, conditions: null,
@ -646,7 +650,7 @@ function emitRecord(rec, line, opts, stylize) {
short = true; short = true;
/* jsl:fall-thru */ /* jsl:fall-thru */
case OM_PAUL: case OM_LONG:
// [time] LEVEL: name[/component]/pid on hostname (src): msg* (extras...) // [time] LEVEL: name[/component]/pid on hostname (src): msg* (extras...)
// msg* // msg*
// -- // --
@ -896,6 +900,10 @@ function emitRecord(rec, line, opts, stylize) {
emit(util.inspect(rec, false, Infinity, true) + '\n'); emit(util.inspect(rec, false, Infinity, true) + '\n');
break; break;
case OM_BUNYAN:
emit(JSON.stringify(rec, null, 0) + '\n');
break;
case OM_JSON: case OM_JSON:
emit(JSON.stringify(rec, null, opts.jsonIndent) + '\n'); emit(JSON.stringify(rec, null, opts.jsonIndent) + '\n');
break; break;

View file

@ -103,8 +103,8 @@ Output options:
Force no coloring (e.g. terminal doesn't support it) Force no coloring (e.g. terminal doesn't support it)
* `-o FORMAT`, `--output FORMAT`: * `-o FORMAT`, `--output FORMAT`:
Specify an output format. One of `paul` (the default), `short`, `json`, Specify an output format. One of `long` (the default), `short`, `json`,
`json-N`, or `inspect`. `json-N`, `bunyan` (the native bunyan 0-indent JSON output) or `inspect`.
* `-j`: * `-j`:
Shortcut for `-o json`. Shortcut for `-o json`.
@ -128,15 +128,16 @@ scripts, uppercase symbols like "DEBUG" are defined for convenience.
## OUTPUT FORMATS ## OUTPUT FORMATS
FORMAT NAME DESCRIPTION FORMAT NAME DESCRIPTION
paul (default) The default output. Long form. Colored and "pretty". long (default) The default output. Long form. Colored and "pretty".
'req' and 'res' and 'err' fields are rendered specially 'req' and 'res' and 'err' fields are rendered specially
as an HTTP request, HTTP response and exception as an HTTP request, HTTP response and exception
stack trace, respectively. Note: the "paul" name stack trace, respectively. For backward compat, the
is deprecated and will be changed to "long". name "paul" also works for this.
short Like the default output, but more concise. Some short Like the default output, but more concise. Some
typically redundant fields are ellided. typically redundant fields are ellided.
json JSON output, 2-space indentation. json JSON output, 2-space indentation.
json-N JSON output, N-space indentation, e.g. "json-0" json-N JSON output, N-space indentation, e.g. "json-4"
bunyan Alias for "json-0", the Bunyan "native" format.
inspect Node.js `util.inspect` output. inspect Node.js `util.inspect` output.

View file

@ -185,6 +185,26 @@ test('multiple logs', function (t) {
}); });
}); });
test('multiple logs, bunyan format', function (t) {
exec(_('%s -o bunyan %s/corpus/log1.log %s/corpus/log2.log', BUNYAN, __dirname, __dirname),
function (err, stdout, stderr) {
t.ifError(err);
t.equal(stdout, [
'{"name":"agent1","pid":73267,"hostname":"headnode","level":30,"msg":"message","time":"2012-05-08T16:57:55.586Z","v":0}',
'{"name":"agent2","pid":73267,"hostname":"headnode","level":30,"msg":"message","time":"2012-05-08T16:58:55.586Z","v":0}',
'{"name":"agent2","pid":73267,"hostname":"headnode","level":30,"msg":"message","time":"2012-05-08T17:01:49.339Z","v":0}',
'{"name":"agent2","pid":73267,"hostname":"headnode","level":30,"msg":"message","time":"2012-05-08T17:02:47.404Z","v":0}',
'{"name":"agent1","pid":73267,"hostname":"headnode","level":30,"msg":"message","time":"2012-05-08T17:02:49.339Z","v":0}',
'{"name":"agent1","pid":73267,"hostname":"headnode","level":30,"msg":"message","time":"2012-05-08T17:02:49.404Z","v":0}',
'{"name":"agent1","pid":73267,"hostname":"headnode","level":30,"msg":"message","time":"2012-05-08T17:02:49.404Z","v":0}',
'{"name":"agent2","pid":73267,"hostname":"headnode","level":30,"msg":"message","time":"2012-05-08T17:02:57.404Z","v":0}',
'{"name":"agent2","pid":76156,"hostname":"headnode","level":30,"msg":"message","time":"2012-05-08T17:08:01.105Z","v":0}',
''
].join('\n'));
t.end();
});
});
test('log1.log.gz', function (t) { test('log1.log.gz', function (t) {
exec(_('%s %s/corpus/log1.log.gz', BUNYAN, __dirname), exec(_('%s %s/corpus/log1.log.gz', BUNYAN, __dirname),
function (err, stdout, stderr) { function (err, stdout, stderr) {