debug: do not seek after creating log file

This commit is contained in:
Alexander Neumann 2015-02-08 14:46:29 +01:00
parent c884704bce
commit 8dc5c2296a
1 changed files with 9 additions and 7 deletions

View File

@ -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)
}