47 lines
1.0 KiB
Go
Raw Normal View History

2024-07-11 16:37:26 +08:00
package log
import (
2024-07-17 23:05:23 +08:00
"context"
2024-07-11 16:37:26 +08:00
"fmt"
2024-07-18 09:51:20 +08:00
"github.com/google/uuid"
2024-07-11 16:37:26 +08:00
"github.com/loveuer/nf"
ulog "github.com/loveuer/nf/nft/log"
)
2024-07-17 23:05:23 +08:00
func _mix(ctx context.Context, msg string) string {
if ctx == nil {
2024-07-18 09:51:20 +08:00
return fmt.Sprintf("%s | %s", uuid.Must(uuid.NewV7()).String(), msg)
2024-07-11 16:37:26 +08:00
}
2024-07-18 09:51:20 +08:00
traceId := ctx.Value(nf.TraceKey)
if traceId == nil {
return fmt.Sprintf("%s | %s", uuid.Must(uuid.NewV7()).String(), msg)
}
return fmt.Sprintf("%s | %s", traceId, msg)
2024-07-11 16:37:26 +08:00
}
2024-07-17 23:05:23 +08:00
func Debug(ctx context.Context, msg string, data ...any) {
ulog.Debug(_mix(ctx, msg), data...)
2024-07-11 16:37:26 +08:00
}
2024-07-17 23:05:23 +08:00
func Info(ctx context.Context, msg string, data ...any) {
ulog.Info(_mix(ctx, msg), data...)
2024-07-11 16:37:26 +08:00
}
2024-07-17 23:05:23 +08:00
func Warn(ctx context.Context, msg string, data ...any) {
ulog.Warn(_mix(ctx, msg), data...)
2024-07-11 16:37:26 +08:00
}
2024-07-17 23:05:23 +08:00
func Error(ctx context.Context, msg string, data ...any) {
ulog.Error(_mix(ctx, msg), data...)
2024-07-11 16:37:26 +08:00
}
2024-07-17 23:05:23 +08:00
func Panic(ctx context.Context, msg string, data ...any) {
ulog.Panic(_mix(ctx, msg), data...)
2024-07-11 16:37:26 +08:00
}
2024-07-17 23:05:23 +08:00
func Fatal(ctx context.Context, msg string, data ...any) {
ulog.Fatal(_mix(ctx, msg), data...)
2024-07-11 16:37:26 +08:00
}