2020-09-09 21:48:27 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"log"
|
|
|
|
)
|
|
|
|
|
2021-10-15 20:22:00 +00:00
|
|
|
func initLogging(logFilePath string) *os.File {
|
2020-09-09 21:48:27 +00:00
|
|
|
f, err := os.OpenFile(logFilePath, os.O_RDWR | os.O_CREATE | os.O_APPEND, 0600)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.SetOutput(f)
|
|
|
|
return f
|
2020-09-09 21:50:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func teardownLogging(f *os.File) {
|
|
|
|
fi, err := f.Stat()
|
|
|
|
if err != nil {
|
2021-10-15 20:22:00 +00:00
|
|
|
panic(err)
|
2020-09-09 21:50:28 +00:00
|
|
|
}
|
|
|
|
if fi.Size() == 0 {
|
2021-10-15 20:22:00 +00:00
|
|
|
err = os.Remove(f.Name())
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2020-09-09 21:50:28 +00:00
|
|
|
}
|
|
|
|
err = f.Close()
|
|
|
|
if err != nil {
|
2021-10-15 20:22:00 +00:00
|
|
|
panic(err)
|
2020-09-09 21:50:28 +00:00
|
|
|
}
|
2020-09-09 21:48:27 +00:00
|
|
|
}
|