2023-07-04 16:56:09 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2023 Laura Kalb <dev@lauka.net>
|
|
|
|
* The code of this project is available under the MIT license. See the LICENSE file for more info.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
package log
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"time"
|
2024-11-06 11:16:12 +01:00
|
|
|
|
|
|
|
"github.com/rs/zerolog"
|
|
|
|
"github.com/rs/zerolog/log"
|
|
|
|
"github.com/spf13/viper"
|
2023-07-04 16:56:09 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
var FlagDebug bool
|
|
|
|
|
|
|
|
func InitializeLogger() {
|
2024-11-06 11:16:12 +01:00
|
|
|
_noColor := !viper.GetBool("logging.colored_output")
|
|
|
|
|
2023-07-07 11:04:15 +02:00
|
|
|
if os.Getenv("INVOCATION_ID") == "" {
|
|
|
|
// detect systemd
|
2024-11-06 11:16:12 +01:00
|
|
|
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stdout, NoColor: _noColor, TimeFormat: time.RFC3339})
|
2023-07-07 11:04:15 +02:00
|
|
|
} else {
|
|
|
|
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stdout, NoColor: true, PartsExclude: []string{"time"}})
|
|
|
|
}
|
2023-07-04 16:56:09 +02:00
|
|
|
|
|
|
|
if FlagDebug {
|
|
|
|
zerolog.SetGlobalLevel(zerolog.DebugLevel)
|
|
|
|
} else {
|
|
|
|
zerolog.SetGlobalLevel(zerolog.InfoLevel)
|
|
|
|
}
|
|
|
|
}
|