Skip to content

Commit 8157209

Browse files
committed
Ignore parsing errors
1 parent bd7cd42 commit 8157209

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

lib/log.js

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,24 +105,32 @@ Log.prototype = {
105105

106106
read: function(){
107107
var buf = ''
108-
, self = this;
109-
this.stream.setEncoding('ascii');
110-
this.stream.on('data', function(chunk){
108+
, self = this
109+
, stream = this.stream;
110+
111+
stream.setEncoding('ascii');
112+
stream.on('data', function(chunk){
111113
buf += chunk;
112114
if ('\n' != buf[buf.length - 1]) return;
113115
buf.split('\n').map(function(line){
114116
if (!line.length) return;
115-
var captures = line.match(/^\[([^\]]+)\] (\w+) (.*)/);
116-
var obj = {
117-
date: new Date(captures[1])
118-
, level: exports[captures[2]]
119-
, levelString: captures[2]
120-
, msg: captures[3]
121-
};
122-
self.emit('line', obj);
117+
try {
118+
var captures = line.match(/^\[([^\]]+)\] (\w+) (.*)/);
119+
var obj = {
120+
date: new Date(captures[1])
121+
, level: exports[captures[2]]
122+
, levelString: captures[2]
123+
, msg: captures[3]
124+
};
125+
self.emit('line', obj);
126+
} catch (err) {
127+
// Ignore
128+
}
123129
});
124130
buf = '';
125-
}).on('end', function(){
131+
});
132+
133+
stream.on('end', function(){
126134
self.emit('end');
127135
});
128136
},

0 commit comments

Comments
 (0)