feat: base implementation

This commit is contained in:
2025-07-20 13:47:16 +02:00
parent ad082a3f12
commit 7d561ea6ea
21 changed files with 635 additions and 0 deletions

View File

@ -0,0 +1,24 @@
package jlog
import (
"io"
"log/slog"
"math/rand"
"os"
"strconv"
)
func New(level slog.Level) *slog.Logger {
return NewFor(level, os.Stderr)
}
func NewFor(level slog.Level, output io.Writer) *slog.Logger {
return slog.New(slog.NewJSONHandler(output, &slog.HandlerOptions{
// AddSource: true,
Level: level,
})).With(slog.String("traceid", newTraceID()))
}
func newTraceID() string {
return strconv.Itoa(rand.Intn(1000000))
}