Switch API to log via ctx instead of to logger struct
Closed this issue · 4 comments
ammario commented
I'm definitely in favor of this change now.
- The alternative is Loggers becoming apart of random objects so their methods have smaller signatures.
- We already store fields as apart of the context, this fits nicely into that model.
- Context-based instrumentation is the basis of the built in trace package and OpenCensus.
cmoog commented
So if I understand correctly, we'd have the following
func process(ctx context.Context) {
slog.Info(ctx, "log message")
}
Wouldn't you lose the ability to specify the io.Writer
to which logs are written? You'd be restricted to a single logger implicit with each context.
But all things considered, I'm in favor as well.
nhooyr commented
@cmoog You'd create a new context with a new logger that writes to wherever you want.
nhooyr commented
i.e ctx = sloghuman.Make(ctx, os.Stdout)