-
Notifications
You must be signed in to change notification settings - Fork 889
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
Conversation
a050167
to
2149092
Compare
2149092
to
b32b696
Compare
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) { |
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.
We should add testing around this. If logging breaks in any way, we really hurt our customers.
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.
@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.
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 like that!
cli/server.go
Outdated
if cfg.Logging.Human.Value == "/dev/stderr" { | ||
sinks = append(sinks, sloghuman.Sink(cmd.ErrOrStderr())) |
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.
Nice touch 👍
cli/server.go
Outdated
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)) | ||
} |
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 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
No description provided.