Browse Source

Add logging

master
Nise Void 2 years ago
parent
commit
783443433e
Signed by: NiseVoid GPG Key ID: FBA14AC83EA602F3
3 changed files with 44 additions and 0 deletions
  1. +2
    -0
      .gitignore
  2. +30
    -0
      logger.go
  3. +12
    -0
      main.go

+ 2
- 0
.gitignore View File

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

+ 30
- 0
logger.go 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
- 0
main.go View File

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


Loading…
Cancel
Save