Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: add stackdriver and json log options to coder server #5682

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

Merged
merged 9 commits into from
Jan 13, 2023

Conversation

coadler
Copy link
Contributor

@coadler coadler commented Jan 11, 2023

No description provided.

@coadler coadler self-assigned this Jan 11, 2023
@coadler coadler force-pushed the colin/server-structured-logs branch from a050167 to 2149092 Compare January 11, 2023 21:17
@coadler coadler force-pushed the colin/server-structured-logs branch from 2149092 to b32b696 Compare January 11, 2023 21:22
@coadler coadler marked this pull request as ready for review January 11, 2023 21:52
@coadler coadler requested a review from a team as a code owner January 11, 2023 21:52
@coadler coadler requested review from presleyp and deansheather and removed request for a team and presleyp January 11, 2023 21:52
cli/server.go Outdated
@@ -1512,3 +1517,64 @@ func redirectHTTPToAccessURL(handler http.Handler, accessURL *url.URL) http.Hand
func isLocalhost(host string) bool {
return host == "localhost" || host == "127.0.0.1" || host == "::1"
}

func makeLogger(cmd *cobra.Command, cfg *codersdk.DeploymentConfig) (slog.Logger, func(), error) {
Copy link
Member

Choose a reason for hiding this comment

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

We should add testing around this. If logging breaks in any way, we really hurt our customers.

Copy link
Member

Choose a reason for hiding this comment

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

@coadler since you can't read sinks from an instantiated logger, you could make this return ([]slog.Sink, slog.Level, func() error) instead and instantiate the logger from the caller.

Copy link
Member

Choose a reason for hiding this comment

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

I like that!

cli/server.go Outdated
Comment on lines 1528 to 1529
if cfg.Logging.Human.Value == "/dev/stderr" {
sinks = append(sinks, sloghuman.Sink(cmd.ErrOrStderr()))
Copy link
Member

Choose a reason for hiding this comment

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

Nice touch 👍

cli/server.go Outdated
Comment on lines 1541 to 1550
if cfg.Logging.JSON.Value == "/dev/stderr" {
sinks = append(sinks, slogjson.Sink(cmd.ErrOrStderr()))
} else {
fi, err := os.OpenFile(cfg.Logging.JSON.Value, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
if err != nil {
return slog.Logger{}, nil, xerrors.Errorf("open json log %q: %w", cfg.Logging.JSON.Value, err)
}
closers = append(closers, fi.Close)
sinks = append(sinks, slogjson.Sink(fi))
}
Copy link
Member

Choose a reason for hiding this comment

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

This whole routine could be made into a little helper function (even just a function stored in a variable at the top of this function would be good) that returns an io.Writer

@coadler coadler merged commit dcab873 into main Jan 13, 2023
@coadler coadler deleted the colin/server-structured-logs branch January 13, 2023 02:08
@github-actions github-actions bot locked and limited conversation to collaborators Jan 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants