WIP: Refactor entire project #16
1 changed files with 28 additions and 0 deletions
28
internal/logger/logger.go
Normal file
28
internal/logger/logger.go
Normal 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()
|
||||
}
|
Loading…
Reference in a new issue