simplelog/json_handler.go

20 lines
374 B
Go

package simplelog
import (
"encoding/json"
"log"
)
type JSONHandler struct{}
func NewJSONHandler() *JSONHandler {
return &JSONHandler{}
}
func (j *JSONHandler) Log(level slog.Level, message string, data ...slog.Field) error {
event := simplelog.NewEvent(level.String(), message, data)
jsonData, _ := json.Marshal(event)
log.Println(string(jsonData))
return nil
}