Commits (2)
  • Rob Swindell's avatar
    get() method supports reading entries from multiple days · 608b6f10
    Rob Swindell authored
    If days_ago argument is undefined (as is the case when performing
    a "last few callers" query/list), then pull upto the maximum last
    number of callers from previous days as necessary.
    
    Part of fix for issue #371
    608b6f10
  • Rob Swindell's avatar
    By default, '-l' (last few callers) option will pull from previous days · 5e428c35
    Rob Swindell authored
    If modopts.ini [logonlist] last_few_days is set (to a number), that will
    dictate the maximum number of previous days to pull last few callers from
    (e.g. set to '0' for previous behavior).
    
    Also, '-l' can now be used with a command-line option (e.g. '-l <num>')
    to specify the number of callers to display (overriding the modopts.ini
    last_fwe_callers value).
    
    This should address issue (feature request) #371.
    5e428c35
...@@ -51,7 +51,24 @@ function get(num, days_ago) ...@@ -51,7 +51,24 @@ function get(num, days_ago)
if(!this.json_lines) if(!this.json_lines)
this.json_lines = load({}, "json_lines.js"); this.json_lines = load({}, "json_lines.js");
return json_lines.get(filename(days_ago), num); var result = json_lines.get(filename(days_ago), num);
if(days_ago !== undefined || typeof result !== 'object')
return result;
if(num < 0)
num += result.length;
else
num -= result.length;
for(days_ago = 1; num != 0; days_ago++) {
var more = json_lines.get(filename(days_ago), num);
if(typeof more !== 'object')
break;
result.push.apply(result, more);
if(num < 0)
num += more.length;
else
num -= more.length;
}
return result;
} }
function maint(backup_level) function maint(backup_level)
......
...@@ -84,9 +84,13 @@ function print(hdr, num, days_ago) ...@@ -84,9 +84,13 @@ function print(hdr, num, days_ago)
return true; return true;
} }
if(argv.indexOf('-l') >= 0) { // Last few callers? var argi = argv.indexOf('-l');
if(argi >= 0) { // Last few callers?
var count = -options.last_few_callers;
if(argi < argc)
count = -parseInt(argv[argi + 1], 10);
if(!this.print(options.last_few_callers_msg || "\x01n\x01g\x01hLast few callers:\x01n\r\n" if(!this.print(options.last_few_callers_msg || "\x01n\x01g\x01hLast few callers:\x01n\r\n"
,-options.last_few_callers)) ,count, options.last_few_days))
console.print(options.first_caller_msg || "\x01n\x01g\x01hYou are the first caller of the day!"); console.print(options.first_caller_msg || "\x01n\x01g\x01hYou are the first caller of the day!");
console.crlf(); console.crlf();
} else { } else {
......