Skip to content

Commit 15873d7

Browse files
committed
make default multi-line separator configurable
1 parent bddbc2f commit 15873d7

3 files changed

Lines changed: 18 additions & 4 deletions

File tree

lib/parser/multiLine.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919
var flatstr = require('flatstr')
2020
var Evt = require('./timerEvent.js')
21-
2221
var timer = new Evt({
2322
interval: Number(process.env.LOGAGENT_MULTILINE_TIMEOUT_MS) || 250,
2423
event: 'timeOut'
@@ -34,12 +33,17 @@ function MultiLine (delimiter, cbf) {
3433
this.consumer = cbf
3534
this.tid = 0
3635
if (delimiter) {
36+
if (!(delimiter instanceof RegExp)) {
37+
this.opt.delimiter = new RegExp(delimiter)
38+
} else {
39+
this.opt.delimiter = delimiter
40+
}
3741
timer.on('timeOut', this.lineTimeout.bind(this))
3842
}
3943
}
4044

4145
MultiLine.prototype.lineTimeout = function () {
42-
if (this.lines.length > 0) {
46+
if (this.lines.length > 0 && (Date.now() - this.timestamp) >= timer.interval) {
4347
this.consumer(flatstr(this.lines.join('\n')))
4448
this.lines.length = 0
4549
this.state = 0
@@ -50,8 +54,8 @@ MultiLine.prototype.add = function (line, cbf) {
5054
if (!this.opt.delimiter) {
5155
return cbf(line)
5256
}
53-
5457
if (this.lines.length === 0) {
58+
this.timestamp = Date.now()
5559
this.lines.push(line)
5660
} else { // reading in block
5761
if (this.opt.delimiter.test(line)) {

lib/parser/parser.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,9 @@ LogParser.prototype = {
244244
this.sources[sourceName].reader = new MultiLine(include[0].blockStart, parser)
245245
return this.sources[sourceName].reader
246246
} else {
247-
this.sources[sourceName].reader = new MultiLine(/^\S+/, parser)
247+
this.sources[sourceName].reader = new MultiLine(
248+
process.env.MULTILINE_DEFAULT_SEPARATOR || this.cfg.multiline.defaultSeparator || /^\S+/,
249+
parser)
248250
return this.sources[sourceName].reader
249251
}
250252
}

patterns.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
# the original line might include sensitive data!
1717
originalLine: false
1818

19+
# default seperator for multiline logs,
20+
# which don't have a blockStart property
21+
# The default /^\S{2,}/ would match typical stack traces
22+
# All lines that start with a whitespace or contain only one char
23+
# would be attached to previous lines
24+
multiline:
25+
defaultSeparator: ^\S{2,}
26+
1927
# Please note when geoIP: true
2028
# There will be a slight delay during first start of logagent while maxmind
2129
# database is downloaded. Logagent downloads the MaxMind database every 24hrs or

0 commit comments

Comments
 (0)