31 lines
600 B
Go
31 lines
600 B
Go
package simplelog
|
|
|
|
import (
|
|
"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
|
|
}
|