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

Seeing double times printed out to stdout

Open jchauncey opened this issue 8 years ago • 8 comments

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?

jchauncey avatar Dec 30 '16 18:12 jchauncey

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.

immesys avatar Feb 12 '17 21:02 immesys

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.

frontierpsycho avatar Mar 13 '17 10:03 frontierpsycho

(note that the example frontierpsycho gave is how it's done in the example in the readme, too)

giftig avatar Mar 15 '17 15:03 giftig

Oh, right, I didn't realize!

Plus, opening a file isn't necessary, Stdout or Stderr are better choices for an example :)

frontierpsycho avatar Mar 15 '17 15:03 frontierpsycho

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

gtt116 avatar Dec 19 '17 08:12 gtt116

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.

gtt116 avatar Dec 19 '17 08:12 gtt116

What's the status of this? Will it not be fixed?

fortuna avatar Aug 16 '18 14:08 fortuna

@fortuna There's nothing to fix; see frontierpsycho's comment from last year.

giftig avatar Aug 16 '18 18:08 giftig