From 8dc5c2296a053435f603aa9362fddb99cfeee55d Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sun, 8 Feb 2015 14:46:29 +0100 Subject: [PATCH] debug: do not seek after creating log file --- debug/debug.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/debug/debug.go b/debug/debug.go index 7b252e1be..4ec274a6b 100644 --- a/debug/debug.go +++ b/debug/debug.go @@ -34,6 +34,15 @@ func initDebugLogger() (lgr *log.Logger) { // open logfile f, err := os.OpenFile(debugfile, os.O_WRONLY|os.O_APPEND, 0600) + if err == nil { + // seek to the end + _, err = f.Seek(2, 0) + if err != nil { + fmt.Fprintf(os.Stderr, "unable to seek to the end of %v: %v\n", debugfile, err) + os.Exit(3) + } + } + if err != nil && os.IsNotExist(err) { // create logfile f, err = os.OpenFile(debugfile, os.O_WRONLY|os.O_CREATE, 0600) @@ -44,13 +53,6 @@ func initDebugLogger() (lgr *log.Logger) { os.Exit(2) } - // seek to the end - _, err = f.Seek(2, 0) - if err != nil { - fmt.Fprintf(os.Stderr, "unable to seek to the end of %v: %v\n", debugfile, err) - os.Exit(3) - } - // open logger lgr = log.New(f, "", log.LstdFlags) }