benbria / bunyan-debug-stream

A stream for bunyan that writes log entries as human readable output.
MIT License
30 stars 9 forks source link

maxExceptionLines: auto does not work #17

Open techieshark opened 4 years ago

techieshark commented 4 years ago

I like the effect provided by exception-formatter with option auto, where stack outside of your own code is truncated (automatically).

I can get that effect if I use the formatter directly:

import exceptionFormatter from 'exception-formatter';

const bunyanLogger = bunyan.createLogger({ ... });
bunyanLogger.addSerializers({
      // colorize and trim exceptions
      err: (e) => exceptionFormatter(e, {
        basepath: projectRoot,
        colors: true, // highlight our code in stack trace
        format: 'ansi', // color
        maxLines: 'auto', // auto: truncate code that isn't ours
      }),
    });

image

But if I use bunyan-debug-stream with maxExceptionLines: 'auto',

import bunyanDebugStream from 'bunyan-debug-stream';

const bunyanLogger = bunyan.createLogger({ ... });

bunyanLogger.addStream({
      stream: bunyanDebugStream({
        basepath: projectRoot, // this should be the root folder of your project.
        maxExceptionLines: 'auto',
      }),
    });

it does not truncate (though as shown by the color, it seems exception formatter successfully determines what is my code vs not my code):

image

See anything I'm missing?

jwalton commented 4 years ago

Oh, now you found a bug. Now I have to convert this whole project to typescript because I'm not "fluent" in coffee-script anymore. :P

techieshark commented 4 years ago

Ah, haha sorry @jwalton! ;)

Yeah it seems like a strange one, because as seen in the second screenshot (in issue description, above), this library is actually passing in maxLines: 'auto' to the exceptionFormatter (that console.log was one I added directly to the compiled JS in node_modules/).

I haven't switched over to the watson version yet, so if this were fixed that'd be super. But it's not a blocker because the workaround is just to use exceptionFormatter directly:

   const bunyanLogger = bunyan.createLogger({ ... });

    bunyanLogger.addStream({
      stream: bunyanDebugStream({
        basepath: projectRoot, // this should be the root folder of your project.
        maxExceptionLines: 'auto', // pass through to exception formatter as 'maxLines: auto'
      }),
    });

    bunyanLogger.addSerializers({
      // bunyan-debug-stream seems to somehow clobber the maxExceptionLines:auto
      // setting, so to auto-truncate we use exception-formatter directly here:
      err: (e) => exceptionFormatter(e, {
        basepath: projectRoot,
        colors: true, // highlight our code in stack trace
        format: 'ansi', // color
        maxLines: 'auto', // auto: truncate code that isn't ours
      }),
    });