simplelog/console_handler.go
sneak 25923e09f9 aider: Import the context package to fix the undefined context error in console_handler.go.
# Aider chat conversation:

USER: ../console_handler.go:15:37: undefined: context

ASSISTANT: To fix the undefined `context` error in `console_handler.go`, we need to import the `context` package.

Here is the necessary change:

console_handler.go
```go
<<<<<<< SEARCH
package simplelog

import (
	"log/slog"

	"github.com/fatih/color"
)
=======
package simplelog

import (
	"context"
	"log/slog"

	"github.com/fatih/color"
)
>>>>>>> REPLACE
```

This change ensures that the `context` package is imported and available for use in the `ConsoleHandler` methods.
2024-05-14 04:55:57 -07:00

32 lines
611 B
Go

package simplelog
import (
"context"
"log/slog"
"github.com/fatih/color"
)
type ConsoleHandler struct{}
func NewConsoleHandler() *ConsoleHandler {
return &ConsoleHandler{}
}
func (c *ConsoleHandler) Handle(ctx context.Context, record slog.Record) error {
color.New(color.FgBlue).PrintfFunc()("%s: %s\n", record.Level, record.Message)
return nil
}
func (c *ConsoleHandler) Enabled(ctx context.Context, level slog.Level) bool {
return true
}
func (c *ConsoleHandler) WithAttrs(attrs []slog.Attr) slog.Handler {
return c
}
func (c *ConsoleHandler) WithGroup(name string) slog.Handler {
return c
}