winston-papertrail icon indicating copy to clipboard operation
winston-papertrail copied to clipboard

Add messageFormat

Open cymen opened this issue 9 years ago • 2 comments

This PR adds a new messageFormat option that is similar to logFormat but operates on the entire message (and passes the meta) whereas logFormat is run on each line of the message.

Example:

In an express app, I'm doing this:

    new winston.transports.Papertrail({
      colorize: false,
      host: 'some-papertrail-host.xyz',
      port: 12345,
      hostname: 'something',
      messageFormat: function(level, _, meta) {
        var msg = meta.req.method + ' ' + meta.req.url + ' ' + meta.res.statusCode + ' ' + meta.responseTime;
        console.log(msg);
        return msg;
      }
    })

cymen avatar Jan 05 '16 00:01 cymen

This PR still has the problem that the meta is also part of the message. That is, if I want to include the message, but only some of the meta (or add extra meta), all the original meta is already part of the message.

I've made a simple fix in my own fork: https://github.com/gunnarlium/winston-papertrail/commit/008e737f54e4c4f25d2b1242764bf7df154fe494

Would you consider incorporating something like this?

gunnarlium avatar Mar 22 '16 09:03 gunnarlium

@kenperkins Any thoughts on this? Would be great to be able to JSON.stringify() meta, which I assume would be possible with this PR.

chmac avatar May 21 '16 15:05 chmac