-
Notifications
You must be signed in to change notification settings - Fork 265
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
Use structured logging with slog #475
Use structured logging with slog #475
Conversation
@benbjohnson I whipped this together based on our conversation earlier. There's a few caveats like with Replica not having the Client on creation time requiring (for now) to use a function to build the logger each time it is used. Some numbers like the WAL index could probably be improved by making it a type alias and having a log formatter function (automatically used by slog) to format it as hex without needing to call Open for initial comments about the whole thing and suggestions what to improve. |
340847e
to
4f89a99
Compare
@benbjohnson rebased and cleaned up, let me know what you think! |
Configuration file can set the logging handler between two: text, which is the default, and json. Default level is info which matches previous behavior. A bit more info level logging is enabled by default to default restore to being verbose compared to quiet and snapshotting. Trace logging has been converted to be on DEBUG level and always enabled if the configured level is high enough. Bumps Go requirement to 1.21
4f89a99
to
f6fe7c4
Compare
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"io" | ||
"log" |
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.
"log" package is still used; see lines 38-41,49.
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.
Right, the Windows build isn't built anymore but the code still exists. It's basically unmaintained so I didn't notice it since I didn't do a Windows build.
I guess it could be fixed but it doesn't really change much.
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.
For what it's worth, Litestream works just fine on Windows after adding imports.
@@ -63,13 +62,13 @@ func (s *windowsService) Execute(args []string, r <-chan svc.ChangeRequest, stat | |||
// Instantiate replication command and load configuration. | |||
c := NewReplicateCommand() | |||
if c.Config, err = ReadConfigFile(DefaultConfigPath(), true); err != nil { | |||
log.Printf("cannot load configuration: %s", err) | |||
slog.Error("cannot load configuration", "error", err) |
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.
"slog" not imported.
Configuration file can set the logging handler between two: text, which is the default, and json. Default level is info which matches previous behavior.
A bit more info level logging is enabled by default to default restore to being verbose compared to quiet and snapshotting.
Trace logging has been converted to be on DEBUG level and always enabled if the configured level is high enough.
Bumps Go requirement to 1.20
Some example output with the default text handler and info level: