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

how to prevent ERROR messages going to stdout ? #30

Open
yonnic opened this issue Sep 26, 2019 · 4 comments
Open

how to prevent ERROR messages going to stdout ? #30

yonnic opened this issue Sep 26, 2019 · 4 comments

Comments

@yonnic
Copy link

yonnic commented Sep 26, 2019

well i saw no way to set a flag or other option to prevent ERROR messages printing in console.
I would like all logger messages to be only in a file

verbose false and system false did not help

@gmassman
Copy link

gmassman commented Dec 16, 2019

I'm getting the same behavior.
In my tests I set up logger like so testLogger := logger.Init("Test", false, false, ioutil.Discard), but still ERROR messages go to stdout. I wouldn't mind working on this if someone from the core team gave me some guidance on how to proceed.

EDIT:
After a little digging, I believe logger.go#L97 is causing the issue. This could be resolved by moving the line inside the if verbose {...}, or adding an option for skipping the eLogs = append(eLogs, os.Stderr).

@adjackura
Copy link
Collaborator

There's not a simple way to get this functionality and keep the API surface for existing users. In our other loggers we moved to options so we could add features like this, but that would be a breaking change here. We could add options on top of the existing arguments to Init though, right now 'stdout' would be the only option.

@gmassman
Copy link

Would it be safe to skip eLogs = append(eLogs, os.Stderr) if the logFile input is ioutil.Discard? The intent is pretty clear that any log data can be thrown away, and this would have a minimum impact on users relying on the existing API.

@dozysun
Copy link

dozysun commented Sep 15, 2020

I think reset writers can solve this problem and doesn't influence existing users:

func (l *Logger) SetOutput(writers ...io.Writer){    
     logLock.Lock()    
     defer logLock.Unlock()
     l.infoLog.SetOutput(io.MultiWriter(writers...))
     l.warningLog.SetOutput(io.MultiWriter(writers...))
     l.errorLog.SetOutput(io.MultiWriter(writers...))
     l.fatalLog.SetOutput(io.MultiWriter(writers...))
}

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

4 participants