mirror of
https://github.com/netbirdio/netbird.git
synced 2024-11-26 01:53:42 +01:00
13b4be31df
* feature: add logging to a file * refactor: move InitLog to util lib * docs: update signal and management docs * chore: update docker compose * set --log-file to console * chore: comment out log volume in docker compose Co-authored-by: mlsmaycon <mlsmaycon@gmail.com>
40 lines
878 B
Go
40 lines
878 B
Go
package util
|
|
|
|
import (
|
|
log "github.com/sirupsen/logrus"
|
|
"gopkg.in/natefinch/lumberjack.v2"
|
|
"io"
|
|
"path/filepath"
|
|
"time"
|
|
)
|
|
|
|
// InitLog parses and sets log-level input
|
|
func InitLog(logLevel string, logPath string) error {
|
|
level, err := log.ParseLevel(logLevel)
|
|
if err != nil {
|
|
log.Errorf("Failed parsing log-level %s: %s", logLevel, err)
|
|
return err
|
|
}
|
|
|
|
if logPath != "" && logPath != "console" {
|
|
lumberjackLogger := &lumberjack.Logger{
|
|
// Log file absolute path, os agnostic
|
|
Filename: filepath.ToSlash(logPath),
|
|
MaxSize: 5, // MB
|
|
MaxBackups: 10,
|
|
MaxAge: 30, // days
|
|
Compress: true,
|
|
}
|
|
log.SetOutput(io.Writer(lumberjackLogger))
|
|
}
|
|
|
|
logFormatter := new(log.TextFormatter)
|
|
logFormatter.TimestampFormat = time.RFC3339 // or RFC3339
|
|
logFormatter.FullTimestamp = true
|
|
|
|
log.SetFormatter(logFormatter)
|
|
log.SetLevel(level)
|
|
|
|
return nil
|
|
}
|