2017-06-18 22:01:44 +00:00
|
|
|
package tools
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
rotatelogs "github.com/lestrrat/go-file-rotatelogs"
|
|
|
|
"github.com/rifflock/lfshook"
|
2017-06-26 18:44:37 +00:00
|
|
|
log "github.com/sirupsen/logrus"
|
2017-06-18 22:01:44 +00:00
|
|
|
)
|
|
|
|
|
2017-06-26 18:44:37 +00:00
|
|
|
// ConfigureLogging configures logrus to our needs
|
|
|
|
func ConfigureLogging() error {
|
2017-06-18 22:01:44 +00:00
|
|
|
|
|
|
|
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,
|
|
|
|
}))
|
2017-06-26 18:44:37 +00:00
|
|
|
|
|
|
|
return nil
|
2017-06-18 22:01:44 +00:00
|
|
|
}
|