veliovgroup/Meteor-logger-console

Exception if data is null

bladerunner2020 opened this issue · 4 comments

There is an exception thrown when I am trying to log information with data = null.
Example of code with error:

     log.info('Some message', null, Meteor.userId());

This code results in exception in line 162.

      if (helpers.isString(data.stackTrace)) {      // <= The wrong line
        data.stackTrace = data.stackTrace.split(/\n\r|\r\n|\r|\n/g);
      }

I believe it's necessary to add a check and the code should be like:

      if (data && helpers.isString(data.stackTrace)) {   
       // ....

PS
The simple solution is to use undefined or {} as data.

Hello @bladerunner2020,

In the docs second argument data has {Object} type
I know null is technically an object, but from the docs it is clear that second argument data should be plain JS object. Hope that helps.

Feel free to close it in case if the issue is solved on your end.

Hello @dr-dimitru,

The seconds arguments could be undefine as well.
So I solved this issue in my code by ensuring that I don't pass null as data.

const data = doSomeStuff();
log.debug('Some message here', data ? data : undefined);

I believe that logger should never throw an exception during logging whichever data it got as arguments, but you may close the issue if you don't agree ))

@bladerunner2020

I'd go with:

const data = doSomeStuff() || undefined;
log.debug('Some message here', data);

I believe that logger should never throw an exception during logging whichever data it got as arguments, but you may close the issue if you don't agree ))

I believe we all should read and follow docs provided along with library we're using.
I agree that exception can be more verbose, I'll keep it for next release.

Hello @bladerunner2020 ,

The fix was implemented in logger and logger-console packages, please upgrade to the latest releases.

Feel free to reopen it in case if the issue is still persists on your end.