mirror of
https://github.com/TecharoHQ/anubis.git
synced 2026-04-16 05:15:03 +00:00
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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user