Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seeing double times printed out to stdout #107

Open
jchauncey opened this issue Dec 30, 2016 · 8 comments
Open

Seeing double times printed out to stdout #107

jchauncey opened this issue Dec 30, 2016 · 8 comments

Comments

@jchauncey
Copy link

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?

@immesys
Copy link

immesys commented Feb 12, 2017

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.

@frontierpsycho
Copy link

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.

@giftig
Copy link
Contributor

giftig commented Mar 15, 2017

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

@frontierpsycho
Copy link

Oh, right, I didn't realize!

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

@gtt116
Copy link

gtt116 commented Dec 19, 2017

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
Copy link

gtt116 commented Dec 19, 2017

Looks like some guy already works on it #39.
But backwards compatibility blocks the PR to be merged.

@fortuna
Copy link

fortuna commented Aug 16, 2018

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

@giftig
Copy link
Contributor

giftig commented Aug 16, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants