You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When looking at many logs at a go, it's often very convenient to filter based on time. A prototype fix, surely incomplete:
diff --git a/bin/bunyan b/bin/bunyan
index 80bd5f0..959518b 100755
--- a/bin/bunyan
+++ b/bin/bunyan
@@ -149,6 +149,15 @@ function printHelp() {
console.log(" use the numeric values for filtering by level.")
console.log(" --strict Suppress all but legal Bunyan JSON log lines. By
console.log(" non-JSON, and non-Bunyan lines are passed throug
+ console.log(" -t, --time TIME");
+ console.log(" Only show messages more recent than the specifie
+ console.log(" expressed as seconds in the past. The time may"
+ console.log(" have an optional 'm', 'd' or 'w' suffix to denot
+ console.log(" minutes, days and weeks, respectively. For exam
+ console.log(" `-t 5m` would emit all Bunyan log lines from wit
+ console.log(" the past five minutes. (Note that non-Bunyan lo
+ console.log(" lines are passed through the time filter; see --
+ console.log(" above.)");
console.log("");
console.log("Output options:");
console.log(" --color Colorize output. Defaults to try if output");
@@ -213,6 +222,16 @@ function filterRecord(rec, opts)
return false;
}
+ if (opts.time) {
+ if (!rec.time)
+ return false;
+
+ var t = new Date(rec.time);
+
+ if (!isNaN(t.valueOf()) && t.valueOf() < opts.time)
+ return false;
+ }
+
if (opts.conditions) {
for (var i = 0; i < opts.conditions.length; i++) {
var pass = opts.conditions[i].runInNewContext(rec);
@@ -303,7 +322,8 @@ function parseArgv(argv) {
jsonIndent: 2,
level: null,
conditions: null,
- strict: false
+ strict: false,
+ time: 0
};
// Turn '-iH' into '-i -H', except for argument-accepting options.
@@ -390,6 +410,21 @@ function parseArgv(argv) {
}
parsed.level = level;
break;
+ case "-t":
+ case "--time":
+ var timeArg = args.shift();
+ var multiplier = { s: 1, m: 60, h: 3600, d: 86400, w: 604800 };
+ var m = 1, t;
+
+ if ((m = multiplier[timeArg[timeArg.length - 1]]) !== undefined)
+ timeArg = timeArg.substr(0, timeArg.length - 1);
+
+ if ((t = parseInt(timeArg, 10)) + '' != timeArg || isNaN(t) || t < 0)
+ throw new Error("invalid time value: '"+timeArg+"'");
+
+ parsed.time = new Date().valueOf() - (t * m * 1000);
+ break;
+
case "-c":
case "--condition":
var condition = args.shift();
The text was updated successfully, but these errors were encountered:
Heh, I had these (in separate places) in my notes:
bunyan -s|--start 5m # start 5 min ago
bunayn -s time=5m
The idea with the latter one is a more generic "start" option that would potentially eventually allow something like this:
bunyan -s req_id=$uuid
That would scan back through the log file(s) looking for the first record with that req_id field (with some max time/num-records/size back as a guard).
bunyan -t 5l # that's a lowercase "L"; last 5 *lines*
RobG recently added napictl lastlog to get the last N logs, so there is a valid use case there I think. And if we did add support for this, what about (a) the mnemonic is not "time", but "tail", and (b) the default would be lines. The "l" is weird as a suffix, so I'd just drop that.
bunyan --tail # last 10 lines (where by "lines" I mean log records)
bunyan -t # ditto
bunyan -t 5 # last 5 lines
bunyan -t 5s # last 5 seconds
bunyan -t 5m # last 5 minutes
Thoughts?
Also, your patch was clipped at 80 columns, cutting off some of your usage text. Can you resubmit that?
When looking at many logs at a go, it's often very convenient to filter based on time. A prototype fix, surely incomplete:
The text was updated successfully, but these errors were encountered: