node-bunyan icon indicating copy to clipboard operation
node-bunyan copied to clipboard

Max log length

Open grahamrhay opened this issue 8 years ago • 6 comments

I use bunyan to log to syslog (stdout > systemd), but if the message logged is too long (e.g. a web service returns an html error page, rather than the expected json) then the json output by bunyan gets split across multiple lines in syslog. Which in turn causes ELK to choke on parsing the log files.

I'm dealing with this by manually truncating the message in places where it has happened (and I've eventually noticed). Would you be open to adding a max message length option? Or is there some existing solution I've missed?

grahamrhay avatar Apr 23 '16 13:04 grahamrhay

Same happens with fluentd. And if the lines are large enough, it can even crash the log parser.

stefaneg avatar May 09 '19 12:05 stefaneg

Was this ever resolved? I'm having the same problem that bunyan is "helping" me by splitting up long messages and changing the syntactic structure in the process. Great feature. How do I shut it off?

CodeBishop avatar Jul 23 '19 22:07 CodeBishop

I just had that too. Didn't expect such inconsistency...

koresar avatar Aug 04 '20 06:08 koresar

In my service I'm handling this in a custom stream, which looks for oversized lines and trims fields (large ones first) until it fits: https://gist.github.com/ikonst/9f3070dbd20440646c9d8dca7c184656

Instead of changing bunyan, you can do

bunyan.create({
  stream: LogStream({ stream: process.stdout, maxLength: 5000 })
})

ikonst avatar Sep 08 '23 04:09 ikonst

I my service we just moved to pino logger, which has same API :) but also much more flexible. I'd recommend.

koresar avatar Sep 20 '23 05:09 koresar

how does pino solve this ^^^ problem?

grahamrhay avatar Sep 20 '23 08:09 grahamrhay