aider: Renamed CustomLogger to CustomHandler.

# Aider chat conversation:

USER: rename CustomLogger to CustomHandler

ASSISTANT: To make this change we need to modify `simplelog.go`:

1. Replace all instances of `CustomLogger` with `CustomHandler`.

Here are the *SEARCH/REPLACE* blocks:

simplelog.go
```go
<<<<<<< SEARCH
type CustomLogger struct {
	handlers []slog.Handler
}

func (cl *CustomLogger) Log(level slog.Level, message string, data ...slog.Field) error {
	for _, handler := range cl.handlers {
		if err := handler.Log(level, message, data...); err != nil {
			return err
		}
	}
	return nil
}

var ourCustomLogger *slog.Logger

func init() {
	ourCustomLogger = NewCustomLogger()
	slog.SetDefault(ourCustomLogger)
}

func NewCustomLogger() *CustomLogger {
	cl := &CustomLogger{}
=======
type CustomHandler struct {
	handlers []slog.Handler
}

func (cl *CustomHandler) Log(level slog.Level, message string, data ...slog.Field) error {
	for _, handler := range cl.handlers {
		if err := handler.Log(level, message, data...); err != nil {
			return err
		}
	}
	return nil
}

var ourCustomLogger *slog.Logger

func init() {
	ourCustomLogger = NewCustomHandler()
	slog.SetDefault(ourCustomLogger)
}

func NewCustomHandler() *CustomHandler {
	cl := &CustomHandler{}
>>>>>>> REPLACE
```
This commit is contained in:
Jeffrey Paul 2024-05-14 04:48:29 -07:00
parent 373dd0ac76
commit 4f26c35da6

View File

@ -13,11 +13,11 @@ var (
webhookURL = os.Getenv("LOGGER_WEBHOOK_URL") webhookURL = os.Getenv("LOGGER_WEBHOOK_URL")
) )
type CustomLogger struct { type CustomHandler struct {
handlers []slog.Handler handlers []slog.Handler
} }
func (cl *CustomLogger) Log(level slog.Level, message string, data ...slog.Field) error { func (cl *CustomHandler) Log(level slog.Level, message string, data ...slog.Field) error {
for _, handler := range cl.handlers { for _, handler := range cl.handlers {
if err := handler.Log(level, message, data...); err != nil { if err := handler.Log(level, message, data...); err != nil {
return err return err
@ -29,12 +29,12 @@ func (cl *CustomLogger) Log(level slog.Level, message string, data ...slog.Field
var ourCustomLogger *slog.Logger var ourCustomLogger *slog.Logger
func init() { func init() {
ourCustomLogger = NewCustomLogger() ourCustomLogger = NewCustomHandler()
slog.SetDefault(ourCustomLogger) slog.SetDefault(ourCustomLogger)
} }
func NewCustomLogger() *CustomLogger { func NewCustomHandler() *CustomHandler {
cl := &CustomLogger{} cl := &CustomHandler{}
if isatty.IsTerminal(os.Stdout.Fd()) { if isatty.IsTerminal(os.Stdout.Fd()) {
cl.handlers = append(cl.handlers, NewConsoleHandler()) cl.handlers = append(cl.handlers, NewConsoleHandler())
} else { } else {