very basic thoughts on module and file structure

basic configuration
basic logger
This commit is contained in:
Jakob Schrettenbrunner
2017-06-19 00:01:44 +02:00
parent 2568d9dd1a
commit 326fdcae6e
8 changed files with 156 additions and 0 deletions

31
tools/logging.go Normal file
View File

@@ -0,0 +1,31 @@
package tools
import (
"time"
log "github.com/Sirupsen/logrus"
rotatelogs "github.com/lestrrat/go-file-rotatelogs"
"github.com/rifflock/lfshook"
)
func ConfigureLogging() {
log.SetFormatter(&log.TextFormatter{
DisableTimestamp: true,
})
path := "logs/"
writer := rotatelogs.New(
path+"pterodactyld.%Y%m%d-%H%M.log",
rotatelogs.WithLinkName(path),
rotatelogs.WithMaxAge(time.Duration(86400)*time.Second),
rotatelogs.WithRotationTime(time.Duration(604800)*time.Second),
)
log.AddHook(lfshook.NewHook(lfshook.WriterMap{
log.InfoLevel: writer,
log.ErrorLevel: writer,
log.FatalLevel: writer,
log.PanicLevel: writer,
}))
}