feat(logging): add option to hide log line source

This is almost certainly going to be a footgun, but it's not too
bad of a change to make. If users really do want to make getting
support more difficult, so be it.

Closes: #1537
Signed-off-by: Xe Iaso <me@xeiaso.net>
This commit is contained in:
Xe Iaso
2026-03-24 15:32:09 +00:00
parent e42a328843
commit 082a57a1a0
7 changed files with 21 additions and 11 deletions

View File

@@ -10,7 +10,7 @@ import (
"strings"
)
func InitSlog(level string, sink io.Writer) *slog.Logger {
func InitSlog(level string, sink io.Writer, hideSource bool) *slog.Logger {
var programLevel slog.Level
if err := (&programLevel).UnmarshalText([]byte(level)); err != nil {
fmt.Fprintf(os.Stderr, "invalid log level %s: %v, using info\n", level, err)
@@ -20,10 +20,16 @@ func InitSlog(level string, sink io.Writer) *slog.Logger {
leveler := &slog.LevelVar{}
leveler.Set(programLevel)
h := slog.NewJSONHandler(sink, &slog.HandlerOptions{
opts := &slog.HandlerOptions{
AddSource: true,
Level: leveler,
})
}
if hideSource {
opts.AddSource = false
}
h := slog.NewJSONHandler(sink, opts)
result := slog.New(h)
return result
}