Skip to content

Instantly share code, notes, and snippets.

@ayapi
Last active January 4, 2016 05:18
Show Gist options
  • Save ayapi/8573800 to your computer and use it in GitHub Desktop.
Save ayapi/8573800 to your computer and use it in GitHub Desktop.
node-bunyanでログファイルがかきこまれたらイベントを発火するょーにしてみた logが増ぇた時にView(node-webkitのDOMとか)を更新したぃとかでっかぇる系
var util = require('util');
var _ = require('lodash');
var bunyan = require('bunyan');
function MyRingBuffer(options){
bunyan.RingBuffer.call(this, arguments)
}
util.inherits(MyRingBuffer, bunyan.RingBuffer);
MyRingBuffer.prototype.write = function(record){
bunyan.RingBuffer.prototype.write.call(this, arguments);
this.emit('write', record);
return true;
};
var ringbuffer = new MyRingBuffer({ limit: 20 });
var log = bunyan.createLogger({
name: 'foo',
streams: [
{
level: 'info',
path: 'example.log'
},
{
level: 'info',
type: 'raw',
stream: ringbuffer
}
]
});
ringbuffer.on('write', function(){
console.log(arguments);
});
_.delay(function(){
log.info('hello world');
}, 1000);
_.delay(function(){
log.info('hello world');
}, 2000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment