37 lines
495 B
Go
37 lines
495 B
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"log"
|
|
)
|
|
|
|
func initLogging() *os.File {
|
|
if len(logFilePath) == 0 {
|
|
return nil
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
func teardownLogging(f *os.File) {
|
|
fi, err := f.Stat()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
if fi.Size() == 0 {
|
|
err = os.Remove(f.Name())
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
err = f.Close()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
} |