Autocreate errors log file

This commit is contained in:
Eugeny Leonov 2022-06-20 14:26:27 +05:00
parent 8278ce50c3
commit 3c0add8c6b
1 changed files with 15 additions and 0 deletions

View File

@ -9,6 +9,21 @@ import (
var errFS *os.File = nil
var errFSLock sync.Mutex
func init() {
bn, e := os.Executable()
if e != nil {
panic("Can not get executable name")
}
ef, e := os.OpenFile(bn+".error", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0665)
if e != nil {
panic("Can not open or create error log file")
}
err := InitFS(ef)
if err != nil {
panic(err)
}
}
func InitFS(f *os.File) *Err {
errFS = f
errFSLock = sync.Mutex{}