파일에 직접 로깅하는 로거로 교체

This commit is contained in:
2023-06-13 20:03:10 +09:00
parent d490188bd2
commit c1847ee3e1
12 changed files with 116 additions and 77 deletions

28
shared/logger.go Normal file
View File

@ -0,0 +1,28 @@
package shared
import (
"log"
"os"
"path"
)
var defLogger *log.Logger
func InitLogger() {
name, _ := os.Executable()
base := path.Base(name)
logfile, _ := os.OpenFile(base+".log", os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0666)
defLogger = log.New(logfile, "", log.LstdFlags)
}
func Logger() *log.Logger {
return defLogger
}
func CloseLogger() {
outfile := defLogger.Writer().(*os.File)
if outfile != nil {
outfile.Close()
}
}