TomFrost / Bristol

Insanely configurable logging for Node.js
MIT License
113 stars 19 forks source link

Pass the unformatted message(s) to the target #56

Open dandv opened 6 years ago

dandv commented 6 years ago

I'm trying to build a target for a cloud logging system (Rollbar) that accepts object parameters in its log calls, and parses that object and displays individual keys in the web UI. A sample log call would be:

logger.info('apples vs. oranges', { apples: foo, oranges: bar });

Problem is that the target function receives the message already formatted as string. Sending that raw string to the logging service is a no-go. In order to reconstruct my original object, I have to JSON.parse() the message argument. This is slow and roundabout.

image

I also need to scrub the severity and message fields from the object, because they're already included in the call itself.

It would be great if Bristol made available the original message arugment(s), perhaps as rest parameters to the target function.

In the meantime, here's the code I'm using:

function rollbarLogger(options, severity, date, messageAlreadyFormatted) {
  const mafObject = JSON.parse(messageAlreadyFormatted);
  const message = mafObject.message;
  delete mafObject.message;
  delete mafObject.severity;
  rollbar[severity](message, mafObject);
}