Skip to content

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

Merged
coadler merged 9 commits into
mainfrom
colin/server-structured-logs
Jan 13, 2023
Merged

feat: add stackdriver and json log options to coder server#5682
coadler merged 9 commits into
mainfrom
colin/server-structured-logs

Conversation

@coadler
Copy link
Copy Markdown
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 deansheather and presleyp and removed request for a team and presleyp January 11, 2023 21:52
Comment thread cli/deployment/config.go
Comment thread cli/server.go Outdated
return host == "localhost" || host == "127.0.0.1" || host == "::1"
}

func makeLogger(cmd *cobra.Command, cfg *codersdk.DeploymentConfig) (slog.Logger, func(), error) {
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

I like that!

Comment thread 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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice touch 👍

Comment thread 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
Copy Markdown
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