TRACE, DEBUG, et al in bunayn -c "..." filter code.

E.g.:
      $ ... | bunyan -c 'level >= ERROR'
This commit is contained in:
Trent Mick 2012-08-08 11:57:13 -07:00
parent 33867b7473
commit 0620b2793d
2 changed files with 21 additions and 2 deletions

View file

@ -2,7 +2,10 @@
## bunyan 0.11.1 (not yet released)
(nothing yet)
- Add defines for the (uppercase) log level names (TRACE, DEBUG, etc.) in
`bunyan -c "..."` filtering condition code. E.g.:
$ ... | bunyan -c 'level >= ERROR'
## bunyan 0.11.0

View file

@ -58,6 +58,8 @@ Object.keys(levelFromName).forEach(function (name) {
name.length === 4 ? ' ' : '') + name.toUpperCase();
});
//---- support functions
function getVersion() {
@ -315,6 +317,20 @@ function parseArgv(argv) {
}
args = newArgs;
var condDefines = [
"var TRACE = 10;",
"var DEBUG = 20;",
"var INFO = 30;",
"var WARN = 40;",
"var ERROR = 50;",
"var FATAL = 60;"
].join('\n') + '\n';
var condDefines = [];
Object.keys(upperNameFromLevel).forEach(function (lvl) {
condDefines.push(format("var %s = %s;", upperNameFromLevel[lvl], lvl));
});
condDefines = condDefines.join('\n') + '\n';
var endOfOptions = false;
while (args.length > 0) {
var arg = args.shift();
@ -371,7 +387,7 @@ function parseArgv(argv) {
var condition = args.shift();
parsed.conditions = parsed.conditions || []
var scriptName = 'bunyan-condition-'+parsed.conditions.length;
var script = vm.createScript(condition, scriptName);
var script = vm.createScript(condDefines + condition, scriptName);
parsed.conditions.push(script);
break
default: // arguments