'--strict' option for CLI
This commit is contained in:
parent
3303b3cb3d
commit
4ad39fe8de
2 changed files with 19 additions and 7 deletions
|
@ -2,7 +2,8 @@
|
||||||
|
|
||||||
## bunyan 0.11.3 (not yet released)
|
## bunyan 0.11.3 (not yet released)
|
||||||
|
|
||||||
(nothing yet)
|
- Add '--strict' option to `bunyan` CLI to suppress all but legal Bunyan JSON
|
||||||
|
log lines. By default non-JSON, and non-Bunyan lines are passed through.
|
||||||
|
|
||||||
|
|
||||||
## bunyan 0.11.2
|
## bunyan 0.11.2
|
||||||
|
|
23
bin/bunyan
23
bin/bunyan
|
@ -145,6 +145,8 @@ function printHelp() {
|
||||||
console.log(" and only show those that resolve to a truish value.");
|
console.log(" and only show those that resolve to a truish value.");
|
||||||
console.log(" E.g. `-c 'pid == 123'`, `-c 'level == 50'`. You must");
|
console.log(" E.g. `-c 'pid == 123'`, `-c 'level == 50'`. You must");
|
||||||
console.log(" use the numeric values for filtering by level.");
|
console.log(" use the numeric values for filtering by level.");
|
||||||
|
console.log(" --strict Suppress all but legal Bunyan JSON log lines. By default");
|
||||||
|
console.log(" non-JSON, and non-Bunyan lines are passed through.");
|
||||||
console.log("");
|
console.log("");
|
||||||
console.log("Output options:");
|
console.log("Output options:");
|
||||||
console.log(" --color Colorize output. Defaults to try if output");
|
console.log(" --color Colorize output. Defaults to try if output");
|
||||||
|
@ -297,7 +299,8 @@ function parseArgv(argv) {
|
||||||
outputMode: OM_PAUL,
|
outputMode: OM_PAUL,
|
||||||
jsonIndent: 2,
|
jsonIndent: 2,
|
||||||
level: null,
|
level: null,
|
||||||
conditions: null
|
conditions: null,
|
||||||
|
strict: false
|
||||||
};
|
};
|
||||||
|
|
||||||
// Turn '-iH' into '-i -H', except for argument-accepting options.
|
// Turn '-iH' into '-i -H', except for argument-accepting options.
|
||||||
|
@ -337,6 +340,9 @@ function parseArgv(argv) {
|
||||||
case "--version":
|
case "--version":
|
||||||
parsed.version = true;
|
parsed.version = true;
|
||||||
break;
|
break;
|
||||||
|
case "--strict":
|
||||||
|
parsed.strict = true;
|
||||||
|
break;
|
||||||
case "--color":
|
case "--color":
|
||||||
parsed.color = true;
|
parsed.color = true;
|
||||||
break;
|
break;
|
||||||
|
@ -465,19 +471,24 @@ function handleLogLine(file, line, opts, stylize) {
|
||||||
// Emit non-JSON lines immediately.
|
// Emit non-JSON lines immediately.
|
||||||
var rec;
|
var rec;
|
||||||
if (!line) {
|
if (!line) {
|
||||||
return emit(line + '\n');
|
if (!opts.strict) emit(line + '\n');
|
||||||
|
return;
|
||||||
} else if (line[0] !== '{') {
|
} else if (line[0] !== '{') {
|
||||||
return emit(line + '\n'); // not JSON
|
if (!opts.strict) emit(line + '\n'); // not JSON
|
||||||
|
return;
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
rec = JSON.parse(line);
|
rec = JSON.parse(line);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
return emit(line + '\n');
|
if (!opts.strict) emit(line + '\n');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isValidRecord(rec))
|
if (!isValidRecord(rec)) {
|
||||||
return emitRecord(rec, line, opts, stylize);
|
if (!opts.strict) emitRecord(rec, line, opts, stylize);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!filterRecord(rec, opts))
|
if (!filterRecord(rec, opts))
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in a new issue