Add logging

This commit is contained in:
Nise Void 2018-05-17 12:11:33 +02:00
parent bfee747b17
commit 783443433e
Signed by: NiseVoid
GPG Key ID: FBA14AC83EA602F3
3 changed files with 44 additions and 0 deletions

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
**/model/tables.go **/model/tables.go
bindata.go bindata.go
log
parser

30
logger.go Normal file
View File

@ -0,0 +1,30 @@
package main
import (
"os"
"os/signal"
"syscall"
"git.fuyu.moe/Fuyu/flog"
)
func setLogger() {
f, err := os.OpenFile(`log`, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
if err != nil {
panic(err)
}
flog.Output = f
flog.MinLevel = flog.LevelInfo
flog.MinStackLevel = flog.LevelWarning
}
func catchSignals() {
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
go func() {
s := <-sc
flog.Info(`Stopping, signal: `, s)
os.Exit(0)
}()
}

12
main.go
View File

@ -9,6 +9,7 @@ import (
"time" "time"
"git.fuyu.moe/5GPowerQuality/parser/internal/model" "git.fuyu.moe/5GPowerQuality/parser/internal/model"
"git.fuyu.moe/Fuyu/flog"
"git.ultraware.nl/NiseVoid/qb/qbdb" "git.ultraware.nl/NiseVoid/qb/qbdb"
"git.ultraware.nl/NiseVoid/qb/qf" "git.ultraware.nl/NiseVoid/qb/qf"
"golang.org/x/net/html/charset" "golang.org/x/net/html/charset"
@ -17,6 +18,17 @@ import (
var db *qbdb.DB var db *qbdb.DB
func main() { func main() {
defer func() {
v := recover()
if v != nil {
flog.Critical(`panic: `, v)
}
}()
setLogger()
flog.Info(`Starting`)
catchSignals()
initDB() initDB()
start := GetStartDate() start := GetStartDate()