-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
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
Updates to slog to make it the default feature-full logger #127
Conversation
…d code for proper source info logging in dev mode
…hat we have access to its method also return SLogger struct from constructors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another thing that could be nice is to have the option to write logs to a file in addition to stdout.
Check bded386 |
logging/slog_logger.go
Outdated
// but can also use a io.MultiWriter(os.Stdout, file) to write to multiple outputs) | ||
// logLevel is the minimum level to log | ||
// logSource if true, adds source information to the log | ||
func NewSlogTextLogger(outputWriter io.Writer, logLevel slog.Level, logSource bool) *SLogger { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel this should expect a log config which should have: env, log level etc - whatever is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we take the entire slog.HandlerOptions
as input then?
So NewSlogTextLogger(outputWriter io.Writer, handerOptions slog.HandlerOptions)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that makes sense or something like
type SLoggerConfig struct {
slog.HandlerOptions
OutputWriter io.Writer
}
@shrimalmadhur wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See 2bfeb3f
logging/slog_logger.go
Outdated
// logSource if true, adds source information to the log | ||
func NewSlogTextLogger(outputWriter io.Writer, logLevel slog.Level, logSource bool) *SLogger { | ||
handler := slog.NewTextHandler(outputWriter, &slog.HandlerOptions{ | ||
Level: logLevel, // prints debug and above |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: // prints this level and above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logging/slog_logger.go
Outdated
// but can also use a io.MultiWriter(os.Stdout, file) to write to multiple outputs) | ||
// logLevel is the minimum level to log | ||
// logSource if true, adds source information to the log | ||
func NewSlogTextLogger(outputWriter io.Writer, logLevel slog.Level, logSource bool) *SLogger { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that makes sense or something like
type SLoggerConfig struct {
slog.HandlerOptions
OutputWriter io.Writer
}
@shrimalmadhur wdyt?
Started looking into slog:
and agree with @dmanc at this point that we should probably start adopting slog as our standard logger everywhere. Been playing with it a bit and our current interface is super limiting wrt what can be done with slog (for eg can't pass a context to logging functions right now, which can be used to also log traceIds). The blog above mentions this
This draft PR is a wip for adding features to the slogger itself. But we'll eventually need to find a way to adapt our main interface, probably in a next PR. This will require more discussions.
Features added thus far:
4c03592Found a much easier way to do this: df441e7