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

Convert from log to slog #154

Merged
merged 1 commit into from
Jul 28, 2023
Merged

Conversation

xonvanetta
Copy link
Contributor

@xonvanetta xonvanetta commented Jul 19, 2023

Converted from log to slog

Default log level is info and default log format is text.
Added json or text handler for slog.
Added log level handler.
Changed all places from log to slog with what I thought was the correct level.
Added test to verify error handling in setuping up slog is working.

Resolves: #151

@xonvanetta
Copy link
Contributor Author

Sorry wrote a better git commit, missed that is it wans't a good enough one

Not sure if I set the correct log levels in the applications, i.e. if some logs should be moved to Debug or to Info but its up for discussion

@xonvanetta xonvanetta changed the title Convert to slog from log Converted from log to slog Jul 19, 2023
Copy link
Contributor

@excalq excalq left a comment

Choose a reason for hiding this comment

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

Looks good. I've been interested in using slog now that it's stable.

@kuskoman
Copy link
Owner

@xonvanetta I will try to take a look on it tommorow

warn := godotenv.Load()
if warn != nil {
log.Println(warn)
err := godotenv.Load()
Copy link
Owner

Choose a reason for hiding this comment

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

since this error is not a critical error, leading to panic i would like you to leave name of the variable as "warn"

Copy link
Contributor Author

@xonvanetta xonvanetta Jul 25, 2023

Choose a reason for hiding this comment

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

I do not agree on this, since the returned interface is an error I would like to use the variable name err, even if it's a trivial error. The problem lies at first glance, I didn't think this was an error type.

But in the end this is just my opinion, will of course change it to warn again :)

Copy link
Owner

Choose a reason for hiding this comment

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

You can change it to something like erorr and criticalError
But I would like to distingiush these two, as godotenv load can safely fail and logger should crash the application in my opinion

}

logger, err := config.SetupSlog()
if err != nil {
Copy link
Owner

Choose a reason for hiding this comment

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

I think in this case we should just crash the application

handler = slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{
Level: level,
})
case "json":
Copy link
Owner

Choose a reason for hiding this comment

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

this case is not tested

@kuskoman
Copy link
Owner

I like where it is going, feel free to convert rest of the log calls to slog calls
Thank you for your work!

@kuskoman kuskoman added enhancement New feature or request go Pull requests that update Go code labels Jul 25, 2023
@xonvanetta
Copy link
Contributor Author

I have fixed the comments and found no more log calls that can be moved to slog

@xonvanetta xonvanetta requested a review from kuskoman July 25, 2023 10:35
@codecov
Copy link

codecov bot commented Jul 25, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (bd01426) 100.00% compared to head (f3b6391) 100.00%.

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #154   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           12        13    +1     
  Lines          570       589   +19     
=========================================
+ Hits           570       589   +19     
Files Changed Coverage Δ
collectors/collector_manager.go 100.00% <100.00%> (ø)
collectors/nodestats/pipeline_subcollector.go 100.00% <100.00%> (ø)
config/slog_config.go 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

executionStatus = "error"
} else {
log.Printf("executor %s succeeded after %s", name, executionDuration)
slog.Info("executor succeeded", "name", name, "duration", executionDuration)
Copy link

Choose a reason for hiding this comment

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

minor: this should also be Debug here

Default log level is `info` and default log format is `text`.
Added json or text handler for slog.
Added log level handler.
Changed all places from log to slog with what I thought was the correct level.
Added test to verify error handling in setuping up slog is working.

Resolves: kuskoman#151
@kuskoman kuskoman changed the title Converted from log to slog Convert from log to slog Jul 28, 2023
@kuskoman kuskoman merged commit cd0f569 into kuskoman:master Jul 28, 2023
@kuskoman
Copy link
Owner

I will leave it for a moment on the master branch before releasing it. You should be able to grab the master version from github actions output

@kercdbh
Copy link

kercdbh commented Aug 1, 2023

I grabbed master from the ghcr.io registry and working as expected; thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request go Pull requests that update Go code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Being able to turn off not important logs
4 participants