Files
unifood/core/services/jlog/logger.go
bdoerfchen ec66365b5e feat: unifood base with GET dishes (#1)
Features:
- CLI structure with verbs and resources
- Application config and parameters
- Output formatters
- Initial resource: dishes

Reviewed-on: #1
Co-authored-by: bdoerfchen <git@bissendorf.co>
Co-committed-by: bdoerfchen <git@bissendorf.co>
2025-07-20 17:29:04 +00:00

25 lines
441 B
Go

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