Skip to content

Commit a58a186

Browse files
committed
Remove empty panic logs on exit.
1 parent a62382c commit a58a186

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

cmd/s2k/main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"os"
66
"path/filepath"
77
"runtime"
8+
"runtime/debug"
89
"time"
910

1011
cli "github.com/urfave/cli/v2"
@@ -201,6 +202,14 @@ To see actual "active" configuration use dry-run mode.
201202
if env.Cfg != nil && len(env.Cfg.Smtp.Dir) > 0 {
202203
os.RemoveAll(env.Cfg.Smtp.Dir)
203204
}
205+
// remove empty panic log if any
206+
if env.Cfg != nil && len(env.Cfg.Logging.FileLogger.Destination) > 0 {
207+
debug.SetCrashOutput(nil, debug.CrashOptions{})
208+
fname := filepath.Join(filepath.Dir(env.Cfg.Logging.FileLogger.Destination), "sync2kindle-panic.log")
209+
if fi, err := os.Stat(fname); err == nil && fi.Size() == 0 {
210+
os.Remove(fname)
211+
}
212+
}
204213
if err != nil {
205214
os.Exit(1)
206215
}

0 commit comments

Comments
 (0)