Merge pull request #2373 from kolyshkin/logging-nits

Logging nits
This commit is contained in:
Mrunal Patel 2020-05-07 20:54:49 -07:00 committed by GitHub
commit 47a7343182
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 7 deletions

View File

@ -60,7 +60,7 @@ checkpointed.`,
return err
}
if status == libcontainer.Created || status == libcontainer.Stopped {
fatalf("Container cannot be checkpointed in %s state", status.String())
fatal(fmt.Errorf("Container cannot be checkpointed in %s state", status.String()))
}
options := criuOptions(context)
if !(options.LeaveRunning || options.PreDump) {

View File

@ -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 {

View File

@ -45,12 +45,20 @@ func checkArgs(context *cli.Context, expected, checkType int) error {
return nil
}
func logrusToStderr() bool {
l, ok := logrus.StandardLogger().Out.(*os.File)
return ok && l.Fd() == os.Stderr.Fd()
}
// fatal prints the error's details if it is a libcontainer specific error type
// then exits the program with an exit status of 1.
func fatal(err error) {
// make sure the error is written to the logger
logrus.Error(err)
fmt.Fprintln(os.Stderr, err)
if !logrusToStderr() {
fmt.Fprintln(os.Stderr, err)
}
os.Exit(1)
}

View File

@ -91,10 +91,6 @@ func getContainer(context *cli.Context) (libcontainer.Container, error) {
return factory.Load(id)
}
func fatalf(t string, v ...interface{}) {
fatal(fmt.Errorf(t, v...))
}
func getDefaultImagePath(context *cli.Context) string {
cwd, err := os.Getwd()
if err != nil {