homebox/backend/app/api/logger.go

25 lines
564 B
Go
Raw Permalink Normal View History

2022-09-04 03:27:02 +00:00
package main
import (
"os"
"github.com/hay-kot/homebox/backend/internal/sys/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 {
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr}).With().Caller().Logger()
2022-09-04 03:27:02 +00:00
}
level, err := zerolog.ParseLevel(a.conf.Log.Level)
if err == nil {
zerolog.SetGlobalLevel(level)
2022-09-04 03:27:02 +00:00
}
}