2022-09-04 03:27:02 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
|
2022-09-24 19:33:38 +00:00
|
|
|
"github.com/hay-kot/homebox/backend/internal/config"
|
2022-09-04 03:27:02 +00:00
|
|
|
"github.com/rs/zerolog"
|
|
|
|
"github.com/rs/zerolog/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
// setupLogger initializes the zerolog config
|
|
|
|
// for the shared logger.
|
|
|
|
func (a *app) setupLogger() {
|
|
|
|
// Logger Init
|
|
|
|
// zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
|
2022-09-14 17:35:23 +00:00
|
|
|
if a.conf.Log.Format != config.LogFormatJSON {
|
2022-10-30 02:15:35 +00:00
|
|
|
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr}).With().Caller().Logger()
|
2022-09-04 03:27:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
log.Level(getLevel(a.conf.Log.Level))
|
|
|
|
}
|
|
|
|
|
|
|
|
func getLevel(l string) zerolog.Level {
|
|
|
|
switch strings.ToLower(l) {
|
|
|
|
case "debug":
|
|
|
|
return zerolog.DebugLevel
|
|
|
|
case "info":
|
|
|
|
return zerolog.InfoLevel
|
|
|
|
case "warn":
|
|
|
|
return zerolog.WarnLevel
|
|
|
|
case "error":
|
|
|
|
return zerolog.ErrorLevel
|
|
|
|
case "fatal":
|
|
|
|
return zerolog.FatalLevel
|
|
|
|
case "panic":
|
|
|
|
return zerolog.PanicLevel
|
|
|
|
default:
|
|
|
|
return zerolog.InfoLevel
|
|
|
|
}
|
|
|
|
}
|