added logger
This commit is contained in:
parent
dbf9ca898f
commit
83a3743104
|
@ -3,6 +3,7 @@
|
|||
*.dll
|
||||
*.so
|
||||
*.dylib
|
||||
lightningTip
|
||||
|
||||
# Test binary, build with `go test -c`
|
||||
*.test
|
||||
|
@ -14,4 +15,7 @@
|
|||
.glide/
|
||||
|
||||
# Jetbrain GoLand
|
||||
.idea
|
||||
.idea
|
||||
|
||||
# Log file
|
||||
lightningTip.log
|
|
@ -0,0 +1,5 @@
|
|||
package main
|
||||
|
||||
func main() {
|
||||
initLog()
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/op/go-logging"
|
||||
"os"
|
||||
)
|
||||
|
||||
var log = logging.MustGetLogger("lightningTip")
|
||||
var logFormat = logging.MustStringFormatter("%{time:2006-01-02 15:04:05.000} [%{level}] %{message}")
|
||||
|
||||
func initLog() {
|
||||
logging.SetFormatter(logFormat)
|
||||
logging.SetLevel(logging.DEBUG, "")
|
||||
|
||||
backendConsole := logging.NewLogBackend(os.Stdout, "", 0)
|
||||
|
||||
logging.SetBackend(backendConsole)
|
||||
|
||||
file, err := os.OpenFile("lightningTip.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0600)
|
||||
|
||||
if err == nil {
|
||||
defer file.Close()
|
||||
|
||||
backendFile := logging.NewLogBackend(file, "", 0)
|
||||
|
||||
logging.SetBackend(backendConsole, backendFile)
|
||||
|
||||
log.Debug("Successfully initialized log file")
|
||||
|
||||
} else {
|
||||
log.Critical("Failed to initialize log file: ", err)
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue