File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1818 */
1919var flatstr = require ( 'flatstr' )
2020var Evt = require ( './timerEvent.js' )
21-
2221var 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
4145MultiLine . 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 ) ) {
Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff line change 1616# the original line might include sensitive data!
1717originalLine : 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
You can’t perform that action at this time.
0 commit comments