We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What is the best approach to tracking which "application subsystem" a message is coming from?
Normally I would create one logger per subsystem and configure its "name" or "channel".
But it seems that channel is only referenced in the record and its using the global DefaultCannelName
DefaultCannelName
in probe.go I have
var probeLogger = slog.NewWithName("probe") func init() { slog.DefaultChannelName = "probe" slog.DefaultTimeFormat = "2006-01-02 15:04:05.000" h1 := handler.NewConsoleHandler(slog.AllLevels) f := slog.AsTextFormatter(h1.Formatter()) f.SetTemplate(utils.LogTemplate) probeLogger.AddHandlers(h1) probeLogger.Infof("Probing %s", viper.GetString("read")) ...
where as in root.go I have
var rootLogger = slog.NewWithName("root") func init() { slog.DefaultChannelName = "root" slog.DefaultTimeFormat = "2006-01-02 15:04:05.000" h1 := handler.NewConsoleHandler(slog.AllLevels) f := slog.AsTextFormatter(h1.Formatter()) f.SetTemplate(utils.LogTemplate) rootLogger.AddHandlers(h1)
All of probe.go's messages are using root
root
I have worked around it by using a subsystem specific template that hardcodes the name, but that seems unclean...
The text was updated successfully, but these errors were encountered:
👍 Thanks for your feedback, I will add logger.ChannelName option setting in next version.
logger.ChannelName
var rootLogger = slog.NewWithName("root", func(l *slog.Logger) { // l.ChannelName = "root" // or l.ChannelName = l.Name() })
if not sets, will use slog. DefaultChannelName.
slog. DefaultChannelName
The time format can be sets by:
f := slog.AsTextFormatter(h1. Formatter()) f.TimeFormat = "2006-01-02 15:04:05.000"
Sorry, something went wrong.
✨ feat: support set default channel name on each logger. issues #108
ccc8922
Super-big thumbs up...
hi @nhi-vanye released on the v0.5.3
inhere
No branches or pull requests
What is the best approach to tracking which "application subsystem" a message is coming from?
Normally I would create one logger per subsystem and configure its "name" or "channel".
But it seems that channel is only referenced in the record and its using the global
DefaultCannelName
in probe.go I have
where as in root.go I have
All of probe.go's messages are using
root
I have worked around it by using a subsystem specific template that hardcodes the name, but that seems unclean...
The text was updated successfully, but these errors were encountered: