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 ```
This commit is contained in:
parent
66aae3d758
commit
7e0266aefc
20
simplelog.go
20
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
|
||||
|
Loading…
Reference in New Issue
Block a user