Skip to content

Commit

Permalink
👔 up: handler - syslog handler write log by log level. fix #142
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Apr 7, 2024
1 parent 70031a7 commit 1b25cfd
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion handler/syslog.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,25 @@ func (h *SysLogHandler) Handle(record *slog.Record) error {
return err
}

return h.writer.Info(string(bts))
s := string(bts)

// write log by level
switch record.Level {
case slog.DebugLevel, slog.TraceLevel:
return h.writer.Debug(s)
case slog.NoticeLevel:
return h.writer.Notice(s)
case slog.WarnLevel:
return h.writer.Warning(s)
case slog.ErrorLevel:
return h.writer.Err(s)
case slog.FatalLevel:
return h.writer.Crit(s)
case slog.PanicLevel:
return h.writer.Emerg(s)
default: // as info level
return h.writer.Info(s)
}
}

// Close handler
Expand Down

0 comments on commit 1b25cfd

Please sign in to comment.