pimterry / loglevel

:ledger: Minimal lightweight logging for JavaScript, adding reliable log level methods to wrap any available console.log methods
MIT License
2.62k stars 157 forks source link

Plugin example - Variadic arguments #91

Closed natlibfi-arlehiko closed 8 years ago

natlibfi-arlehiko commented 8 years ago

Hi,

The plugin example in README doesn't support variadic arguments, so writing plugins based on the example won't work as expected (In case the user wants to do log.error('foo', 'bar') instead of log.error('foobar')).

Maybe something like this would be better:

 return function () {

  var messages = ["Newsflash: "];

  for (var i = 0; i < arguments.length; i++) {
    messages.push(arguments[i]);
  }

  rawMethod.apply(undefined, messages);

};

Sure, it looks a lot more complicated. Maybe including both of the examples would be best.