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))
}
