From 0620b2793de18d2f755567448fa6362152cb5d03 Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Wed, 8 Aug 2012 11:57:13 -0700 Subject: [PATCH] TRACE, DEBUG, et al in `bunayn -c "..."` filter code. E.g.: $ ... | bunyan -c 'level >= ERROR' --- CHANGES.md | 5 ++++- bin/bunyan | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 3f82bdf..18d2164 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 diff --git a/bin/bunyan b/bin/bunyan index f8cec2a..549dec0 100755 --- a/bin/bunyan +++ b/bin/bunyan @@ -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