diff options
author | Benjamin Chausse <benjamin.chausse@goto.com> | 2025-03-26 10:52:14 -0400 |
---|---|---|
committer | Benjamin Chausse <benjamin.chausse@goto.com> | 2025-03-26 10:52:14 -0400 |
commit | 04213e975c46b0d6bfecc8695801b85c3f3dd0ab (patch) | |
tree | 73d39c5f614c83baad5eb6ad8669a27750770e2a /internal/logging | |
parent | cd9338e0d6cf582f9ea8028661ac3729e408f3bf (diff) |
charmbracelet/glamour for help + man page generate
Diffstat (limited to 'internal/logging')
-rw-r--r-- | internal/logging/discard.go | 25 | ||||
-rw-r--r-- | internal/logging/logging.go | 8 |
2 files changed, 26 insertions, 7 deletions
diff --git a/internal/logging/discard.go b/internal/logging/discard.go new file mode 100644 index 0000000..e827287 --- /dev/null +++ b/internal/logging/discard.go @@ -0,0 +1,25 @@ +package logging + +import ( + "context" + "log/slog" +) + +// DiscardHandler discards all log output. DiscardHandler.Enabled returns false for all Levels. +type DiscardHandler struct{} + +func (d DiscardHandler) Enabled(ctx context.Context, level slog.Level) bool { + return false +} + +func (d DiscardHandler) Handle(ctx context.Context, record slog.Record) error { + return nil +} + +func (d DiscardHandler) WithAttrs(attrs []slog.Attr) slog.Handler { + return d +} + +func (d DiscardHandler) WithGroup(name string) slog.Handler { + return d +} diff --git a/internal/logging/logging.go b/internal/logging/logging.go index 71f0334..054b303 100644 --- a/internal/logging/logging.go +++ b/internal/logging/logging.go @@ -7,12 +7,6 @@ import ( "github.com/ChausseBenjamin/termpicker/internal/util" ) -type logSink struct{} - -func (l logSink) Write(p []byte) (n int, err error) { - return len(p), nil -} - func Setup(filepath string) *os.File { if filepath != "" { logFile, err := os.Create(filepath) @@ -28,7 +22,7 @@ func Setup(filepath string) *os.File { } else { // Since app is a TUI, logging to stdout/stderr would break the UI // So we disable it by default - handler := slog.NewJSONHandler(logSink{}, nil) + handler := DiscardHandler{} slog.SetDefault(slog.New(handler)) return nil } |