Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Ignore parsing errors
  • Loading branch information
tj committed Sep 26, 2010
1 parent bd7cd42 commit 8157209
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions lib/log.js
Expand Up @@ -105,24 +105,32 @@ Log.prototype = {

read: function(){
var buf = ''
, self = this;
this.stream.setEncoding('ascii');
this.stream.on('data', function(chunk){
, self = this
, stream = this.stream;

stream.setEncoding('ascii');
stream.on('data', function(chunk){
buf += chunk;
if ('\n' != buf[buf.length - 1]) return;
buf.split('\n').map(function(line){
if (!line.length) return;
var captures = line.match(/^\[([^\]]+)\] (\w+) (.*)/);
var obj = {
date: new Date(captures[1])
, level: exports[captures[2]]
, levelString: captures[2]
, msg: captures[3]
};
self.emit('line', obj);
try {
var captures = line.match(/^\[([^\]]+)\] (\w+) (.*)/);
var obj = {
date: new Date(captures[1])
, level: exports[captures[2]]
, levelString: captures[2]
, msg: captures[3]
};
self.emit('line', obj);
} catch (err) {
// Ignore
}
});
buf = '';
}).on('end', function(){
});

stream.on('end', function(){
self.emit('end');
});
},
Expand Down

0 comments on commit 8157209

Please sign in to comment.