Option to cancel timestamp output
mdigger opened this issue · 2 comments
mdigger commented
func (opts Options) NewHandler(w io.Writer) slog.Handler {
// ...
// if h.timeFormat == "" {
// h.timeFormat = defaultTimeFormat
// }
// ...
}
func (h *handler) Handle(_ context.Context, r slog.Record) error {
// ...
// write time, level, and message
if h.timeFormat != "" {
buf.WriteString("\033[2m")
*buf = r.Time.AppendFormat(*buf, h.timeFormat)
buf.WriteString("\033[0m ")
}
lmittmann commented
The feature would be useful, but I am not convinced this is the right way to handle it. The default should include a timestamp and this change would require setting a timestamp format explicitly.
telemachus commented
The feature would be useful, but I am not convinced this is the right way to handle it. The default should include a timestamp and this change would require setting a timestamp format explicitly.
Another option is to support slog's ReplaceAttr
function. If that function is available, you can do something like this:
if h.replaceAttr != nil {
timeAttr = h.replaceAttr(nil, timeAttr)
}
if !timeAttr.Equal(slog.Attr{}) {
// Add timeAttr to the buffer...
}