fix logs
This commit is contained in:
parent
7a0564a210
commit
9979a1eba8
2 changed files with 41 additions and 16 deletions
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"runtime"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
|
@ -62,12 +61,6 @@ func (h *TaskHandler) Handle(ctx context.Context, r slog.Record) error {
|
|||
if !r.Time.IsZero() {
|
||||
buf = h.appendAttr(buf, slog.Time(slog.TimeKey, r.Time))
|
||||
}
|
||||
buf = h.appendAttr(buf, slog.Any(slog.LevelKey, r.Level))
|
||||
if r.PC != 0 {
|
||||
fs := runtime.CallersFrames([]uintptr{r.PC})
|
||||
f, _ := fs.Next()
|
||||
buf = h.appendAttr(buf, slog.String(slog.SourceKey, fmt.Sprintf("%s:%d", f.File, f.Line)))
|
||||
}
|
||||
buf = h.appendAttr(buf, slog.String(slog.MessageKey, r.Message))
|
||||
// Handle state from WithGroup and WithAttrs.
|
||||
goas := h.goas
|
||||
|
@ -108,7 +101,7 @@ func (h *TaskHandler) appendAttr(buf []byte, a slog.Attr) []byte {
|
|||
buf = fmt.Appendf(buf, "%s: %q\n", a.Key, a.Value.String())
|
||||
case slog.KindTime:
|
||||
// Write times in a standard way, without the monotonic time.
|
||||
buf = fmt.Appendf(buf, "%s: %s\n", a.Key, a.Value.Time().Format(time.RFC3339Nano))
|
||||
buf = fmt.Appendf(buf, "%s: %s\n", a.Key, a.Value.Time().Format(time.DateTime))
|
||||
case slog.KindGroup:
|
||||
attrs := a.Value.Group()
|
||||
// Ignore empty groups.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue