Permalink
Browse files

Added `-f, --ignore-eof` support to jog(1)

  • Loading branch information...
tj committed Apr 9, 2012
1 parent 62d3ec3 commit 3bbb42c80d144ab124c79dbde45b74130d425f20
Showing with 46 additions and 8 deletions.
  1. +13 −3 Readme.md
  2. +22 −5 bin/jog
  3. +11 −0 examples/levels.js
View
@@ -106,16 +106,17 @@ yields:
```
Usage: jog [options]
-
+
Options:
-
+
-h, --help output usage information
-V, --version output the version number
+ -f, --ignore-eof do not stop on EOF
-F, --file <path> load from the given <path>
-R, --redis load from redis store
-s, --select <fn> use the given <fn> for filtering
-m, --map <fn> use the given <fn> for mapping
- -c, --color enable colors for json output
+ -c, --color color the json output
```
### Examples
@@ -156,6 +157,15 @@ jog --file /var/log/videos.log --select "_.vid < 5" --map _.msg --map "_.split('
[ 'compiling', 'video' ] ]
```
+ Tail errors only, with color:
+
+```
+$ jog --file my.log -f -c --select '_.level == "error"'
+{ level: 'error',
+ msg: 'something broke',
+ timestamp: 1333943982669 }
+```
+
## Stores
By default Jog ships with the `FileStore` and `RedisStore`, however anything
View
27 bin/jog
@@ -17,6 +17,7 @@ program.on('map', function(val){
program
.version(jog.version)
+ .option('-f, --ignore-eof', 'do not stop on EOF')
.option('-F, --file <path>', 'load from the given <path>')
.option('-R, --redis', 'load from redis store')
.option('-s, --select <fn>', 'use the given <fn> for filtering')
@@ -40,10 +41,14 @@ if (!store) throw new Error('store required, use --file or --redis');
if (program.select) select = new Function('_', 'return ' + program.select);
+// -f
+
+var ignoreEOF = program.ignoreEof;
+
// setup
var log = jog(store)
- , stream = log.stream()
+ , stream = log.stream({ end: !ignoreEOF })
, results = []
, prop;
@@ -63,15 +68,27 @@ stream.on('data', function(line){
ret = maps[i](ret);
}
- results.push(ret);
+ if (ignoreEOF) {
+ output(ret);
+ } else {
+ results.push(ret);
+ }
});
// output results
stream.on('end', function(){
+ ignoreEOF || output(results);
+});
+
+/**
+ * Output `obj`.
+ */
+
+function output(obj) {
if (program.color) {
- console.log(util.inspect(results, false, 15, true));
+ console.log(util.inspect(obj, false, 15, true));
} else {
- console.log(results);
+ console.log(obj);
}
-});
+}
View
@@ -0,0 +1,11 @@
+
+var Jog = require('..')
+ , log = new Jog(new Jog.FileStore('/tmp/levels.log'));
+
+setInterval(function(){
+ log.info('something happened');
+}, 1000);
+
+setInterval(function(){
+ log.error('something broke');
+}, 4000);

0 comments on commit 3bbb42c

Please sign in to comment.