@@ -6,6 +6,9 @@ var fs = require('fs')
66 , moment = require ( 'moment' )
77 , liner = require ( './liner' ) ;
88
9+ var dateStart , dateEnd ;
10+
11+
912/**
1013 * displayError
1114 * Display error messages in red
@@ -29,6 +32,14 @@ function processLine(line) {
2932 } else if ( program . prettydate ) {
3033 text = moment ( jsObj . time ) . format ( "MMMM Do YYYY, hh:mm:ss a" ) + ' | ' ;
3134 }
35+
36+ if ( program . dates ) {
37+ var logEntryDate = moment ( jsObj . time ) . unix ( ) ;
38+ if ( logEntryDate < dateStart || logEntryDate > dateEnd ) {
39+ return null ;
40+ }
41+ }
42+
3243 if ( program . expression ) {
3344 try {
3445 var result = eval ( 'jsObj.' + program . expression ) ;
@@ -67,6 +78,7 @@ function main() {
6778 . version ( '0.0.1' )
6879 . usage ( '[options] bunyan.log' )
6980 . option ( '-a, --array' , 'Output results in array format' )
81+ . option ( '-d, --dates [start,end]' , 'Specify a date range' )
7082 . option ( '-e, --expression [expression]' , 'Filter using expression predicate' )
7183 . option ( '-s, --source' , 'Extract source (JSON) object' )
7284 . option ( '-t, --timestamp' , 'Show timestamp in results' )
@@ -83,6 +95,16 @@ function main() {
8395 console . log ( '[' ) ;
8496 }
8597
98+ if ( program . dates ) {
99+ var dates = program . dates . split ( ',' ) ;
100+ if ( dates . length !== 2 ) {
101+ displayError ( 'date range should consist of two commas separated dates' ) ;
102+ process . exit ( - 1 ) ;
103+ }
104+ dateStart = moment ( dates [ 0 ] . trim ( ) ) . unix ( ) ;
105+ dateEnd = ( dates [ 1 ] . trim ( ) === 'now' ) ? moment ( ) . unix ( ) : moment ( dates [ 1 ] . trim ( ) ) . unix ( ) ;
106+ }
107+
86108 source . pipe ( liner ) ;
87109 source . on ( 'error' , function ( err ) {
88110 if ( err . errno === 34 ) {
@@ -96,7 +118,9 @@ function main() {
96118 var lineIn , lineOut ;
97119 while ( lineIn = liner . read ( ) ) {
98120 lineOut = processLine ( lineIn ) ;
99- console . log ( lineOut + ( ( arrayOutput ) ? ',' : '' ) ) ;
121+ if ( lineOut ) {
122+ console . log ( lineOut + ( ( arrayOutput ) ? ',' : '' ) ) ;
123+ }
100124 }
101125 } ) ;
102126 process . on ( 'exit' , function ( ) {
0 commit comments