-
-
Notifications
You must be signed in to change notification settings - Fork 51
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
add slog and json log option #194
base: master
Are you sure you want to change the base?
Conversation
@@ -118,6 +118,8 @@ type options struct { | |||
Dry bool `long:"dry" env:"DRY" description:"dry mode, no bans"` | |||
Dbg bool `long:"dbg" env:"DEBUG" description:"debug mode"` | |||
TGDbg bool `long:"tg-dbg" env:"TG_DEBUG" description:"telegram debug mode"` | |||
|
|||
LoggingFormat string `long:"logging-format" env:"LOGGING_FORMAT" default:"text" description:"logging format, 'json' or 'text'"` |
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.
This should be added to the README, probably to the list of parameters. It may also be worth mentioning in the detailed explanation of the parameters as well.
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.
fixed, but my formatter did some changes in the readme, I hope you don't mind, they do not look destructive to me
app/main.go
Outdated
} | ||
logOpts = append(logOpts, lgr.Map(colorizer)) | ||
var logger *slog.Logger | ||
if loggingFormat == "json" { |
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.
My brain is going to explode by those nested else/ifs ;) It would be nice to simplify it and make it as plain as possible. Maybe a top-level switch with an early exit will help.
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.
fixed
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 have not checked all the places where you replaced logging, but it seems to be a technical search/replace type of thing. Hopefully, you tried to run it and found no issues.
just a couple of minor things, nothing major. Also, please rebase with the current master, as it has a new PR merged in with some logging changes as well.
as we discussed, i tried to change standard log to structured logging.
So added flag
--logging-format
Example:
--logging-format=json
which is default has
text
value, so the default format of logs mostly was not changed.You also asked to "be careful" so I mostly save the DEBUG LEVEL format of messages by using fmt.
All other logs levels should be "native" for the SLOG format.