added logger

This commit is contained in:
michael1011 2018-03-22 19:03:54 +01:00
parent dbf9ca898f
commit 83a3743104
No known key found for this signature in database
GPG Key ID: 84D249BA71685D46
4 changed files with 47 additions and 1 deletions

6
.gitignore vendored
View File

@ -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

3
build.sh Normal file
View File

@ -0,0 +1,3 @@
gofmt -s -w .
go build -o lightningTip.

5
lightningtip.go Normal file
View File

@ -0,0 +1,5 @@
package main
func main() {
initLog()
}

34
log.go Normal file
View File

@ -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)
}
}