Repository navigation
slog support #6
Description
Activity
API could be like
what.Handler(myLogger); what.Slog("a", 1, "b", 2). Handler sets the slog Handler, and Slog sends messages to it.Hi Carlana, that's an interesting idea.
From my point of view,
whatand logging serve different purposes.- logging supports observability in production while also helping with debugging
whatis a pure ad-hoc “information dumping” tool that is meant to be active during development only (and be non-existent in production code).
Hence I don't see the advantage of “marrying” both concepts (but I am happy to learn).
What problem wouldwhat.Slog()solve?I find the output of slog easier to read because I have it colorized in dev. That would be the big advantage to me. That said, I’m not sure if it would make sense to retrofit an existing package with a clear scope of work.
I see, you want to use
slogto get nicely coloredwhatoutput. I like the idea.What colorizer would you use?
I tried
lmittmann/tint, but most of the colorization is about log levels (plus some grey for the attribute names and the time), so I would have to addwhat.Info(),what.Warn(),what.Error(), andwhat.Debug()functions to get a decent colorization. I feel that's a bit of an overkill. If leveled logging is required, I'd useslogdirectly. I would rather want to implement your minimal suggestion using justwhat.Slog(), with a default handler that does some nice auto-colorization based on ... ? attribute names? attribute position?My current attempt using
tint:var logger = slog.New( // set lmittmann/tint as the global logger's handler // colorable enables color output on Windows tint.NewHandler(colorable.NewColorableStderr(), &tint.Options{ Level: slog.LevelInfo, TimeFormat: time.Kitchen, }), ) func SlogHandler(h slog.Handler) { logger = slog.New(h) } func Slog(msg string, args ...any) { logger.Info(msg, args...) }

I wrote my own colorizer: https://github.com/spotlightpa/almanack/blob/master/pkg/almlog/colorize.go
Reacted by Christoph BergerLost track of this over the holiday season...
I modified
what.Happens()to take Slog-like arguments if the format string is one of "DEBUG", "INFO", "WARN", or "ERROR". Example:what.Happens("INFO", "something happened", "count", 3, "sum", 10)
I took your colorize.go as a starting point, @carlmjohnson, and implemented something similar but without involving
slog. The changes have not been tagged yet; you can test it at commit b5d6749 if you like.Reacted by Carlana
It would be nice to support log/slog. Maybe it should be a new library though.