Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Okhlopkov <[email protected]>
  • Loading branch information
Pavel Okhlopkov committed Oct 21, 2024
1 parent 1b8b06d commit ed0cef8
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions pkg/unilogger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ func NewLogger(opts Options) *Logger {
opts.Output = os.Stdout
}

if opts.TimeFunc == nil {
opts.TimeFunc = func(t time.Time) time.Time {
return t
}
}

l := &Logger{
addSource: &opts.AddSource,
level: &opts.Level,
Expand All @@ -59,7 +65,7 @@ func NewLogger(opts Options) *Logger {
Level: l.level,
ReplaceAttr: func(_ []string, a slog.Attr) slog.Attr {
switch a.Key {
// skip standard fields
// skip standart fields
case slog.LevelKey, slog.MessageKey, slog.TimeKey:
return slog.Attr{}
case slog.SourceKey:
Expand All @@ -76,10 +82,10 @@ func NewLogger(opts Options) *Logger {
s.Line,
))
default:
key := strings.SplitN(a.Key, ";", 1)
key := strings.SplitN(a.Key, ";", 2)
if key[0] == "raw" {
a.Key = strings.Join(key[1:], ";")
a.Value = slog.StringValue(fmt.Sprintf("%#v", a.Value.Any()))
a.Value = slog.StringValue(fmt.Sprintf("%v", a.Value.Any()))
}
}

Expand Down Expand Up @@ -196,11 +202,11 @@ func (l *Logger) Fatalf(format string, args ...any) {
func getStack() string {
rawstack := string(debug.Stack())
rawstack = strings.ReplaceAll(rawstack, "\t", "")
split := strings.Split(rawstack, "\n")
splitted := strings.Split(rawstack, "\n")

split = split[2:]
splitted = splitted[2:]

return strings.Join(split, "")
return strings.Join(splitted, "")
}

func ParseLevel(rawLogLevel string) (Level, error) {
Expand Down

0 comments on commit ed0cef8

Please sign in to comment.