feat: base implementation
This commit is contained in:
24
core/services/jlog/logger.go
Normal file
24
core/services/jlog/logger.go
Normal 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))
|
||||
}
|
||||
Reference in New Issue
Block a user