golog icon indicating copy to clipboard operation
golog copied to clipboard

Time format in log entries

Open dcosson opened this issue 13 years ago • 3 comments

Looks like the time format is hardcoded in the Process() function https://github.com/moovweb/golog/blob/master/processor.go#L52-52

I'd like to log the timestamp in a simpler to parse (and sort) format - would you accept a pull request that adds another field to the LogProcessor for time format and then calls time.Format() with that string?

I was thinking that providing an empty string (or the string "default" or somthing) would use the current behavior with Sprintf, since apparently that's slightly faster than time.Format

dcosson avatar Oct 08 '12 21:10 dcosson

This would be fine with me as long as the code is kept backwards compatible. Do you already have the changes ready? If not, I could implement a new Processor initializer that would allow for a time format argument.

mdayaram avatar Oct 08 '12 21:10 mdayaram

I actually took it one step further and created a new ParsableProcessor type. IMO it was cleaner than adding extra fields & initializer functions for the DefaultProcessor while keeping it everything backwards compatible, and it also lets you specify a field separator for the logger.

So my output using it looks something like this:

// set up with TimeFormat: "2006-01-02T15:04:05" and FieldSeparator: "|"
2012-10-08T23:25:52|INFO|Logger prefix text|the log message here

my changes are https://github.com/dcosson/golog/compare/feature_parsable_processor. Curious to get your opinions

dcosson avatar Oct 08 '12 23:10 dcosson

I like it! Feel free to send a pull request whenever!

mdayaram avatar Oct 08 '12 23:10 mdayaram