go-logging
go-logging copied to clipboard
Seeing double times printed out to stdout
I'm seeing the time printed out twice when doing a logger.Debugf
2016/12/30 18:47:34 2016-12-30T18:47:34.318:
logging.MustStringFormatter(
%{color}%{time:2006-01-02T15:04:05.000}: %{module} -> %{message} %{color:reset})
Suggestions?
I have a similar problem. The time does not appear in my format string (and I don't want it to be there) but I still see the time printed out.
The underlying LogBackend, even though it isn't very well documented, is basically a golang standard library logger. The default logger adds its own time at the beginning of log lines, which you can disable by setting the flag
argument to 0.
If that's too theoretical, this is how to do it with go-logging
:
file, _ := os.Open(logFilePath) // don't ignore error in production
logBackend := logging.NewLogBackend(file, "", 0)
logging.SetBackend(logBackend)
This will make ALL logging get rid of the time in the beginning of the line, so you can add your own in the format.
(note that the example frontierpsycho gave is how it's done in the example in the readme, too)
Oh, right, I didn't realize!
Plus, opening a file isn't necessary, Stdout or Stderr are better choices for an example :)
That same case here
package main
import (
"github.com/op/go-logging"
)
func main() {
log_name := ""
log := logging.MustGetLogger(log_name)
format := logging.MustStringFormatter("%{time} %{color}%{level:.5s}%{color:reset} %{message}")
logging.SetFormatter(format)
log.Info("haha")
}
The output looks like below, but I don't want the double time show in log, do I missing something?
2017/12/19 16:00:08 2017-12-19T16:00:08.333+08:00 INFO haha
Looks like some guy already works on it https://github.com/op/go-logging/pull/39. But backwards compatibility blocks the PR to be merged.
What's the status of this? Will it not be fixed?
@fortuna There's nothing to fix; see frontierpsycho's comment from last year.