-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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 log/slog for structured logging #3502
base: master
Are you sure you want to change the base?
Conversation
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.
Thank you @seankhliao, I really appreciate you tackling this.
I'm mostly satisfied with how things look. I made a few comments, curious what you think.
cmd/dex/serve.go
Outdated
"go_version", runtime.Version(), | ||
"go_os", runtime.GOOS, | ||
"go_arch", runtime.GOARCH, |
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: I wonder if using slog's group feature here would make sense. As far as I understand, that basically means using dot-notated labels (ie. go.version
instead of go_version
).
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 changed it to use groups.
It'll be go.version
in the text output, and in json "go": {"version": ...}
cmd/dex/serve.go
Outdated
formatter.f = &logrus.TextFormatter{DisableColors: true} | ||
slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{ | ||
Level: level, | ||
}) | ||
case "json": | ||
formatter.f = &logrus.JSONFormatter{} | ||
slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{ | ||
Level: level, | ||
}) |
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.
Although I don't think it makes a lot of difference, this changes where logs go (stdout instead of stderr).
We should at least highlight it somewhere.
WDYT @nabokihms ?
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 changed it to stdout. I just wasn't sure which one it should have gone to.
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.
Can be a problem, but mentioning it in the changelog should be fine enough.
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.
sorry I meant I changed it back to stderr.
if c.BaseURL == "" { | ||
return nil, fmt.Errorf("crowd: no baseURL provided for crowd connector") | ||
} | ||
return &crowdConnector{Config: *c, logger: logger}, nil | ||
return &crowdConnector{Config: *c, logger: logger.With("connector_type", "atlassiancrowd", "connector_id", id)}, nil |
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.
Same thing about connectors: maybe use slog.Group
?
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.
updated to use groups too
a5a5908
to
45e201f
Compare
Signed-off-by: Sean Liao <sean+git@liao.dev>
Overview
Switches pkg/log and logrus for the standard library's slog logger.
What this PR does / why we need it
This is more or less a mechanical replacement of the internal
log.Logger
interface andlogrus
logger with the standard library's slog.This appears to be the general community consensus on a standard logging interface, where slog.Logger is used as the common interface, and implementations can switch out the
slog.Handler
if necessary.Connectors have their type and id added as attributes.
Log lines are lowercased for consistency.
Closes #2020
Special notes for your reviewer
If dex is used as a library, this will be a breaking change.
Log line output will be different from before.