fix: JSONHandler deadlock from recursive log.Println (closes #3) #4
@ -3,8 +3,9 @@ package simplelog
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"log"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
type JSONHandler struct{}
|
type JSONHandler struct{}
|
||||||
@ -15,7 +16,7 @@ func NewJSONHandler() *JSONHandler {
|
|||||||
|
|
||||||
func (j *JSONHandler) Handle(ctx context.Context, record slog.Record) error {
|
func (j *JSONHandler) Handle(ctx context.Context, record slog.Record) error {
|
||||||
jsonData, _ := json.Marshal(record)
|
jsonData, _ := json.Marshal(record)
|
||||||
log.Println(string(jsonData))
|
fmt.Fprintln(os.Stdout, string(jsonData))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user