feat(internal/logger): add logger package with different style presets

This commit is contained in:
Tom Neuber 2024-08-19 14:12:00 +02:00
parent 638bb23b90
commit 840008df2d
Signed by: tom
GPG key ID: F17EFE4272D89FF6

28
internal/logger/logger.go Normal file
View file

@ -0,0 +1,28 @@
package logger
import (
"fmt"
"io"
"path/filepath"
"time"
"github.com/rs/zerolog"
)
func CliLoggerLayout(out io.Writer) zerolog.Logger {
zerolog.CallerMarshalFunc = func(_ uintptr, file string, line int) string {
return fmt.Sprintf("%s:%d", filepath.Base(file), line)
}
if zerolog.GlobalLevel() == zerolog.DebugLevel {
debugOutput := zerolog.ConsoleWriter{Out: out, TimeFormat: time.RFC3339}
return zerolog.New(debugOutput).With().Timestamp().Caller().Logger()
}
output := zerolog.ConsoleWriter{Out: out, PartsExclude: []string{"time", "level"}}
return zerolog.New(output).With().Logger()
}
func JSONLoggerLayout(out io.Writer) zerolog.Logger {
return zerolog.New(out).With().Timestamp().Caller().Logger()
}