go-logging icon indicating copy to clipboard operation
go-logging copied to clipboard

The default backend was printing the date and time before the message

Open jeffwilliams opened this issue 11 years ago • 6 comments

The default backend was printing the date and time before the message.

This means that the default formatter was printing the date instead of just the message as documented, and setting a custom format for the default log would have the time prepended to the message.

For example, this code:

package main

import (
  "github.com/op/go-logging"
  //"github.com/jeffwilliams/go-logging"
)

func main() {
  var format = logging.MustStringFormatter(
    "%{color}%{time:15:04:05.000000} %{shortfunc} \u25b6 %{level:.4s} %{id:03x}%{color:reset} %{message}",
  )
  logging.SetFormatter(format)

  var log = logging.MustGetLogger("sandbox")

  log.Debug("msg")
  log.Info("msg")
  log.Warning("msg")
}

Outputs these logs:

2014/12/03 13:34:30 13:34:30.511036 main \u25b6 DEBU 001 msg
2014/12/03 13:34:30 13:34:30.511092 main \u25b6 INFO 002 msg
2014/12/03 13:34:30 13:34:30.511121 main \u25b6 WARN 003 msg

jeffwilliams avatar Dec 03 '14 18:12 jeffwilliams

I agree that it would make life easier to get rid of all the flags passed to the log module. But, I'd prefer to define a nicer default than only the message.

op avatar Dec 08 '14 20:12 op

Hmm, you're probably right. I've changed it so the default is now the date, time and the message. How does that look?

jeffwilliams avatar Dec 20 '14 19:12 jeffwilliams

Looks like that broke a bunch of tests. Let me look into it.

jeffwilliams avatar Dec 20 '14 19:12 jeffwilliams

Unit tests fixed.

jeffwilliams avatar Dec 20 '14 20:12 jeffwilliams

Sorry for the delay. Will need to think about this since this change breaks backwards compatibility.

op avatar Nov 24 '15 21:11 op

No problems! Let me know if you need anything from my side.

On Tue, Nov 24, 2015 at 4:58 PM, Örjan Persson [email protected] wrote:

Sorry for the delay. Will need to think about this since this change breaks backwards compatibility.

— Reply to this email directly or view it on GitHub https://github.com/op/go-logging/pull/39#issuecomment-159417612.

jeffwilliams avatar Dec 04 '15 17:12 jeffwilliams