mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-10 21:53:57 +08:00
Don't print errors twice
Function fatal() and method (*FatalWriter).Write log the error to the logger when prints it to stderr just be be sure. Since by default the logger is configured to write to os.Stderr, we get something like this as a result: > # ./runc checkpoint xx5 > ERRO[0000] Container cannot be checkpointed in stopped state > Container cannot be checkpointed in stopped state or > # ./runc sdf > ERRO[0000] No help topic for 'sdf' > No help topic for 'sdf' This is very annoying. To fix, check if logrus is logging into stderr, and if it is, skip the second write. After this commit: > # ./runc sdf > ERRO[0000] No help topic for 'sdf' > [root@kir-rhat runc]# ./runc --log=out sdf > No help topic for 'sdf' Note that now the logrus prefix might be in or out, depending on whether logrus is logging to stderr or not. This is not perfect, but better than the old behavior. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
@@ -159,7 +159,10 @@ type FatalWriter struct {
|
||||
|
||||
func (f *FatalWriter) Write(p []byte) (n int, err error) {
|
||||
logrus.Error(string(p))
|
||||
return f.cliErrWriter.Write(p)
|
||||
if !logrusToStderr() {
|
||||
return f.cliErrWriter.Write(p)
|
||||
}
|
||||
return len(p), nil
|
||||
}
|
||||
|
||||
func createLogConfig(context *cli.Context) logs.Config {
|
||||
|
||||
Reference in New Issue
Block a user