Skip to content
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

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open

add slog and json log option #194

wants to merge 14 commits into from

Conversation

avonar
Copy link

@avonar avonar commented Dec 8, 2024

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.

@avonar avonar requested a review from umputun as a code owner December 8, 2024 19:37
@@ -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'"`
Copy link
Owner

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.

Copy link
Author

@avonar avonar Dec 11, 2024

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" {
Copy link
Owner

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Owner

@umputun umputun left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants