logr icon indicating copy to clipboard operation
logr copied to clipboard

Consider allowing PC to be passed into Handler

Open thockin opened this issue 2 years ago • 3 comments

This would make bridging from slog a bit cleaner, rather than handlers doing their own unwinding.

thockin avatar Aug 04 '23 16:08 thockin

I had considered this. It seems doable.

I did not pursue it further because it won't work with current LogSink implementations. If we expect implementations to be modified, wouldn't it be better to support slog directly?

pohly avatar Aug 04 '23 17:08 pohly

https://github.com/go-logr/logr/pull/204

I did it and then realized exactrly what you said.

thockin avatar Aug 04 '23 18:08 thockin

The alternative is an interface that is specific to slog:

// SlogSink is an interface that a LogSink can implement to support logging
// through the slog.Logger or slog.Handler APIs better. It then should
// also support special slog values like slog.Group.
type SlogSink interface {
	logr.LogSink

	Handle(ctx context.Context, record slog.Record) error
	WithAttrs(attrs []slog.Attr) SlogSink
	WithGroup(name string) SlogSink
}

I'll prepare a PR with that once https://github.com/go-logr/logr/pull/205 is merged.

pohly avatar Aug 08 '23 05:08 pohly