chore: reverse the coupling of module log and config (#1606)
This way the config module can already use the log module with the same result (default logging to StdOut with Level INFO, same output as before) but ENV variables can already change the logging of config file related log output). It is now possible to dump as a cronjob without having to filter the default log about the used config file. Also: - all logging modules are now configurable when initializing which makes testing easier - viper dependency removed from logging - log correct settings when configured error level is invalid - deprecation of value "false" for log.standard and log.events (already not mentioned in https://vikunja.io/docs/config-options/) Co-authored-by: Berengar W. Lehr <Berengar.Lehr@uni-jena.de> Reviewed-on: https://kolaente.dev/vikunja/api/pulls/1606 Reviewed-by: konrad <k@knt.li> Co-authored-by: Peter H0ffmann <hoffmannp@noreply.kolaente.de> Co-committed-by: Peter H0ffmann <hoffmannp@noreply.kolaente.de>
This commit is contained in:
@ -21,7 +21,6 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"code.vikunja.io/api/pkg/config"
|
||||
"github.com/ThreeDotsLabs/watermill"
|
||||
"github.com/op/go-logging"
|
||||
)
|
||||
@ -34,8 +33,9 @@ type WatermillLogger struct {
|
||||
logger *logging.Logger
|
||||
}
|
||||
|
||||
func NewWatermillLogger() *WatermillLogger {
|
||||
lvl := strings.ToUpper(config.LogEventsLevel.GetString())
|
||||
// NewXormLogger creates and initializes a new watermill logger
|
||||
func NewWatermillLogger(configLogEnabled bool, configLogEvents string, configLogEventsLevel string) *WatermillLogger {
|
||||
lvl := strings.ToUpper(configLogEventsLevel)
|
||||
level, err := logging.LogLevel(lvl)
|
||||
if err != nil {
|
||||
Criticalf("Error setting events log level %s: %s", lvl, err.Error())
|
||||
@ -45,11 +45,14 @@ func NewWatermillLogger() *WatermillLogger {
|
||||
logger: logging.MustGetLogger(watermillLogModule),
|
||||
}
|
||||
|
||||
cf := config.LogEvents.GetString()
|
||||
var backend logging.Backend
|
||||
backend = &NoopBackend{}
|
||||
if cf != "off" && cf != "false" {
|
||||
logBackend := logging.NewLogBackend(GetLogWriter("events"), "", 0)
|
||||
if configLogEvents == "false" {
|
||||
configLogEvents = "off"
|
||||
Warning("log.events value 'false' is deprecated and will be removed in a future release. Please use the value 'off'.")
|
||||
}
|
||||
if configLogEnabled && configLogEvents != "off" {
|
||||
logBackend := logging.NewLogBackend(GetLogWriter(configLogEvents, "events"), "", 0)
|
||||
backend = logging.NewBackendFormatter(logBackend, logging.MustStringFormatter(watermillFmt+"\n"))
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user