ajbrown / angular-loggly-logger

An AngularJS module which sends your $log message to loggly, and provides a service for manually sending messages to loggly.
MIT License
32 stars 49 forks source link

Support customizing `timestamp`, `level` labels. #46

Closed jaketodaro closed 8 years ago

jaketodaro commented 8 years ago

It would be nice to have the ability to customize the label for the timestamp field that includeTimestamp automatically sets (or any other preset field). This would be useful for anyone who wants to maintain a consistent format with other logs that are being sent to loggly from non-angular sources.

This could easily be supported by adding .labels function that accepts an object of label overrides. I'm happy to send a PR if this is approved.

logger
    .includeTimestamp(true)
    .labels({
        timestamp: 'dt',
        level: 'lvl'
    });

Alternatively, you could add support for specifying functions as fields so that users could add the timestamp themselves, but that leads to the possibility of having js errors in your logging. You could even bind the log context to the functions to give them access to some log information like the log level. Happy to send a PR for this too.

logger
    .fields({
        dt: function() { return (new Date()).toISOString() }
        lvl: function() { return this.level }
    });
ajbrown commented 8 years ago

@jaketodaro I like the first approach. My first thought was to add a second (optional) argument to includeTimestamp, but I like the fact that your approach allows cleanly modifying any of the labels.

If you want to do a PR for it, go ahead. (Make sure you target develop)

ajbrown commented 8 years ago

Fixed via #52