remove old log files if they exist

pull/15/head
alok 7 years ago
parent fa42bc3db2
commit 6dbe544abd
  1. 10
      benchmark_main.go

@ -85,6 +85,16 @@ func main() {
// Setup a logger to stdout and log file. // Setup a logger to stdout and log file.
logFileName := fmt.Sprintf("./%v/%v.log", *logFolder, *port) logFileName := fmt.Sprintf("./%v/%v.log", *logFolder, *port)
_, err := os.Stat(logFileName)
if err == nil {
fmt.Printf("file %s exists", logFileName)
os.Remove(logFileName)
fmt.Printf("removed file %s", logFileName)
} else if os.IsNotExist(err) {
fmt.Printf("file %s not exists", logFileName)
} else {
fmt.Printf("file %s stat error: %v", logFileName, err)
}
h := log.MultiHandler( h := log.MultiHandler(
log.Must.FileHandler(logFileName, log.LogfmtFormat()), log.Must.FileHandler(logFileName, log.LogfmtFormat()),
log.StdoutHandler) log.StdoutHandler)

Loading…
Cancel
Save