-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sinks to receive error/trace, and proxy to serialize access
- Loading branch information
Showing
10 changed files
with
481 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package errsink | ||
|
||
import ( | ||
"context" | ||
"log/slog" | ||
) | ||
|
||
type Interface interface { | ||
Put(context.Context, error) | ||
} | ||
|
||
// Nop is an ErrorSink that does nothing. It does not require | ||
// any initialization, so the zero value can be used. | ||
type Nop struct{} | ||
|
||
// NewNop returns a new NopErrorSink object. The constructor | ||
// is provided for consistency. | ||
func NewNop() Interface { | ||
return Nop{} | ||
} | ||
|
||
// Put for NopErrorSink does nothing. | ||
func (Nop) Put(context.Context, error) {} | ||
|
||
type SlogLogger interface { | ||
Log(context.Context, slog.Level, string, ...any) | ||
} | ||
|
||
type slogSink struct { | ||
logger SlogLogger | ||
} | ||
|
||
// NewSlog returns a new ErrorSink that logs errors using the provided slog.Logger | ||
func NewSlog(l SlogLogger) Interface { | ||
return &slogSink{ | ||
logger: l, | ||
} | ||
} | ||
|
||
func (s *slogSink) Put(ctx context.Context, v error) { | ||
s.logger.Log(ctx, slog.LevelError, v.Error()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.