-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: reject unsupported features and log ignored features
Signed-off-by: Ben Meier <[email protected]>
- Loading branch information
1 parent
724a1fc
commit bd89822
Showing
5 changed files
with
131 additions
and
34 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
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,39 @@ | ||
package logging | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
"log/slog" | ||
"sync" | ||
) | ||
|
||
type SimpleHandler struct { | ||
Writer io.Writer | ||
Level slog.Leveler | ||
|
||
mu sync.Mutex | ||
} | ||
|
||
func (h *SimpleHandler) Enabled(ctx context.Context, level slog.Level) bool { | ||
return level >= h.Level.Level() | ||
} | ||
|
||
func (h *SimpleHandler) Handle(ctx context.Context, record slog.Record) error { | ||
h.mu.Lock() | ||
defer h.mu.Unlock() | ||
_, err := h.Writer.Write([]byte(fmt.Sprintf("%s: %s\n", record.Level.String(), record.Message))) | ||
return err | ||
} | ||
|
||
func (h *SimpleHandler) WithAttrs(attrs []slog.Attr) slog.Handler { | ||
// no support for attrs here | ||
return h | ||
} | ||
|
||
func (h *SimpleHandler) WithGroup(name string) slog.Handler { | ||
// no support for attrs here | ||
return h | ||
} | ||
|
||
var _ slog.Handler = (*SimpleHandler)(nil) |