From 7e0266aefc4b9595656b7a58e3d66e1ed06a3b8e Mon Sep 17 00:00:00 2001 From: sneak Date: Tue, 14 May 2024 05:26:56 -0700 Subject: [PATCH] aider: Rename CustomHandler to MultiplexHandler. # Aider chat conversation: USER: rename CustomHandler to MultiplexHandler ASSISTANT: Here are the necessary changes to rename `CustomHandler` to `MultiplexHandler`: simplelog.go ```go <<<<<<< SEARCH ourCustomHandler = NewCustomHandler() ======= ourCustomHandler = NewMultiplexHandler() >>>>>>> REPLACE ``` simplelog.go ```go <<<<<<< SEARCH type CustomHandler struct { ======= type MultiplexHandler struct { >>>>>>> REPLACE ``` simplelog.go ```go <<<<<<< SEARCH func NewCustomHandler() slog.Handler { cl := &CustomHandler{} ======= func NewMultiplexHandler() slog.Handler { cl := &MultiplexHandler{} >>>>>>> REPLACE ``` simplelog.go ```go <<<<<<< SEARCH func (cl *CustomHandler) Handle(ctx context.Context, record slog.Record) error { ======= func (cl *MultiplexHandler) Handle(ctx context.Context, record slog.Record) error { >>>>>>> REPLACE ``` simplelog.go ```go <<<<<<< SEARCH func (cl *CustomHandler) Enabled(ctx context.Context, level slog.Level) bool { ======= func (cl *MultiplexHandler) Enabled(ctx context.Context, level slog.Level) bool { >>>>>>> REPLACE ``` simplelog.go ```go <<<<<<< SEARCH func (cl *CustomHandler) WithAttrs(attrs []slog.Attr) slog.Handler { newHandlers := make([]ExtendedHandler, len(cl.handlers)) for i, handler := range cl.handlers { newHandlers[i] = handler.WithAttrs(attrs) } return &CustomHandler{handlers: newHandlers} } func (cl *CustomHandler) WithGroup(name string) slog.Handler { newHandlers := make([]ExtendedHandler, len(cl.handlers)) for i, handler := range cl.handlers { newHandlers[i] = handler.WithGroup(name) } return &CustomHandler{handlers: newHandlers} ======= func (cl *MultiplexHandler) WithAttrs(attrs []slog.Attr) slog.Handler { newHandlers := make([]ExtendedHandler, len(cl.handlers)) for i, handler := range cl.handlers { newHandlers[i] = handler.WithAttrs(attrs) } return &MultiplexHandler{handlers: newHandlers} } func (cl *MultiplexHandler) WithGroup(name string) slog.Handler { newHandlers := make([]ExtendedHandler, len(cl.handlers)) for i, handler := range cl.handlers { newHandlers[i] = handler.WithGroup(name) } return &MultiplexHandler{handlers: newHandlers} >>>>>>> REPLACE ``` --- simplelog.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/simplelog.go b/simplelog.go index 4d9f449..77b165c 100644 --- a/simplelog.go +++ b/simplelog.go @@ -19,17 +19,17 @@ var ourCustomLogger *slog.Logger var ourCustomHandler slog.Handler func init() { - ourCustomHandler = NewCustomHandler() + ourCustomHandler = NewMultiplexHandler() ourCustomLogger = slog.New(ourCustomHandler) slog.SetDefault(ourCustomLogger) } -type CustomHandler struct { +type MultiplexHandler struct { handlers []ExtendedHandler } -func NewCustomHandler() slog.Handler { - cl := &CustomHandler{} +func NewMultiplexHandler() slog.Handler { + cl := &MultiplexHandler{} if isatty.IsTerminal(os.Stdout.Fd()) { cl.handlers = append(cl.handlers, NewConsoleHandler()) } else { @@ -52,7 +52,7 @@ func NewCustomHandler() slog.Handler { return cl } -func (cl *CustomHandler) Handle(ctx context.Context, record slog.Record) error { +func (cl *MultiplexHandler) Handle(ctx context.Context, record slog.Record) error { for _, handler := range cl.handlers { if err := handler.Handle(ctx, record); err != nil { return err @@ -61,25 +61,25 @@ func (cl *CustomHandler) Handle(ctx context.Context, record slog.Record) error { return nil } -func (cl *CustomHandler) Enabled(ctx context.Context, level slog.Level) bool { +func (cl *MultiplexHandler) Enabled(ctx context.Context, level slog.Level) bool { // send us all events return true } -func (cl *CustomHandler) WithAttrs(attrs []slog.Attr) slog.Handler { +func (cl *MultiplexHandler) WithAttrs(attrs []slog.Attr) slog.Handler { newHandlers := make([]ExtendedHandler, len(cl.handlers)) for i, handler := range cl.handlers { newHandlers[i] = handler.WithAttrs(attrs) } - return &CustomHandler{handlers: newHandlers} + return &MultiplexHandler{handlers: newHandlers} } -func (cl *CustomHandler) WithGroup(name string) slog.Handler { +func (cl *MultiplexHandler) WithGroup(name string) slog.Handler { newHandlers := make([]ExtendedHandler, len(cl.handlers)) for i, handler := range cl.handlers { newHandlers[i] = handler.WithGroup(name) } - return &CustomHandler{handlers: newHandlers} + return &MultiplexHandler{handlers: newHandlers} } type ExtendedEvent interface { GetID() uuid.UUID