mirror of
https://github.com/chainguard-dev/clog
synced 2026-07-06 22:12:46 +00:00
gcp: Refactor to pass in custom writer (#52)
This enables the ability to output to custom writers (e.g. TeeWriters) if necessary.
This commit is contained in:
parent
5a063eb822
commit
3bef2b2727
1 changed files with 8 additions and 1 deletions
|
|
@ -2,6 +2,7 @@ package gcp
|
|||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"log/slog"
|
||||
"os"
|
||||
)
|
||||
|
|
@ -15,8 +16,14 @@ type Handler struct {
|
|||
handler slog.Handler
|
||||
}
|
||||
|
||||
// NewHandler returns a new Handler that writes to stderr.
|
||||
func NewHandler(level slog.Level) *Handler {
|
||||
return &Handler{handler: slog.NewJSONHandler(os.Stderr, &slog.HandlerOptions{
|
||||
return NewHandlerForWriter(os.Stderr, level)
|
||||
}
|
||||
|
||||
// NewHandlerForWriter returns a new Handler that writes to the given writer.
|
||||
func NewHandlerForWriter(w io.Writer, level slog.Level) *Handler {
|
||||
return &Handler{handler: slog.NewJSONHandler(w, &slog.HandlerOptions{
|
||||
AddSource: true,
|
||||
Level: level,
|
||||
ReplaceAttr: func(groups []string, a slog.Attr) slog.Attr {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue