31 lines
695 B
Go
31 lines
695 B
Go
/*
|
|
* 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 (
|
|
"github.com/rs/zerolog"
|
|
"github.com/rs/zerolog/log"
|
|
"os"
|
|
"time"
|
|
)
|
|
|
|
var FlagDebug bool
|
|
|
|
func InitializeLogger() {
|
|
if os.Getenv("INVOCATION_ID") == "" {
|
|
// detect systemd
|
|
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.RFC3339})
|
|
} else {
|
|
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stdout, NoColor: true, PartsExclude: []string{"time"}})
|
|
}
|
|
|
|
if FlagDebug {
|
|
zerolog.SetGlobalLevel(zerolog.DebugLevel)
|
|
} else {
|
|
zerolog.SetGlobalLevel(zerolog.InfoLevel)
|
|
}
|
|
}
|