파일에 직접 로깅하는 로거로 교체
This commit is contained in:
28
shared/logger.go
Normal file
28
shared/logger.go
Normal 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()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user