Skip to content

Commit

Permalink
slogutil: imp code
Browse files Browse the repository at this point in the history
  • Loading branch information
Mizzick committed Oct 18, 2024
1 parent b50b124 commit da3d5e0
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions logutil/slogutil/slogutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func New(c *Config) (l *slog.Logger) {
case FormatJSONL:
h = NewJSONHybridHandler(output, &slog.HandlerOptions{
Level: lvl,
ReplaceAttr: newJSONLReplaceAttr(),
ReplaceAttr: newJSONLReplaceAttr(!c.AddTimestamp),
})
case FormatText:
h = slog.NewTextHandler(output, &slog.HandlerOptions{
Expand Down Expand Up @@ -141,7 +141,11 @@ func ReplaceLevel(groups []string, a slog.Attr) (res slog.Attr) {

// newJSONLReplaceAttr is a function that returns
// [slog.HandlerOptions.ReplaceAttr] function for [FormatJSONHybrid] format.
func newJSONLReplaceAttr() func(groups []string, a slog.Attr) (res slog.Attr) {
func newJSONLReplaceAttr(removeTime bool) func(groups []string, a slog.Attr) (res slog.Attr) {
if !removeTime {
return SimplifyLevel
}

return func(groups []string, a slog.Attr) (res slog.Attr) {
return SimplifyLevel(groups, RemoveTime(groups, a))
}
Expand Down

0 comments on commit da3d5e0

Please sign in to comment.