Skip to content

Instantly share code, notes, and snippets.

@piscis
Created September 6, 2012 08:28
Show Gist options
  • Save piscis/3653048 to your computer and use it in GitHub Desktop.
Save piscis/3653048 to your computer and use it in GitHub Desktop.
Formats a logfile with json objects seperated by linebreaks and prettyfies it
/**
* npm install carrier
* npm install parser
* tail -f /tmp/json.log | node logtest.js
*
* Logfile example:
* {"level":"info","message":"beep boop"}
* {"level":"error","message":"foo bar"}
*/
var carrier = require('carrier');
var parser = carrier.carry(process.stdin);
var util = require('util');
var prettyjson = require('prettyjson');
parser.on('line', function(line) {
var d = JSON.parse(line);
console.log(prettyjson.render(d));
});
process.stdin.resume();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment