Skip to content

Commit

Permalink
promslog: Only log basename, not full path
Browse files Browse the repository at this point in the history
Signed-off-by: Julien <roidelapluie@o11y.eu>
  • Loading branch information
roidelapluie committed Oct 8, 2024
1 parent dae848d commit 1cf530c
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions promslog/slog.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ var (

return a
}
truncateSourceAttrFunc = func(groups []string, a slog.Attr) slog.Attr {
if a.Key != slog.SourceKey {
return a
}
src, _ := a.Value.Any().(*slog.Source)
a.Value = slog.StringValue(filepath.Base(src.File) + ":" + strconv.Itoa(src.Line))
return a
}
)

// AllowedLevel is a settable identifier for the minimum level a log entry
Expand Down Expand Up @@ -165,8 +173,9 @@ func New(config *Config) *slog.Logger {
}

logHandlerOpts := &slog.HandlerOptions{
Level: config.Level.lvl,
AddSource: true,
Level: config.Level.lvl,
AddSource: true,
ReplaceAttr: truncateSourceAttrFunc,
}

if config.Style == GoKitStyle {
Expand Down

0 comments on commit 1cf530c

Please sign in to comment.