-
Notifications
You must be signed in to change notification settings - Fork 6
/
log.go
91 lines (74 loc) · 3.09 KB
/
log.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package slogctx
import (
"context"
"log/slog"
)
// Info calls Info on the default logger.
func Info(msg string, args ...any) {
wrap(context.Background(), DefaultLogger(), slog.LevelInfo, msg, args...)
}
// InfoContext calls InfoContext on the context logger.
// If a Logger is found in the context, it will be used.
func InfoContext(ctx context.Context, msg string, args ...any) {
wrap(ctx, FromContext(ctx), slog.LevelInfo, msg, args...)
}
// Infof calls Infof on the default logger.
func Infof(format string, args ...any) {
wrapf(context.Background(), DefaultLogger(), slog.LevelInfo, format, args...)
}
// InfoContextf calls InfoContextf on the context logger.
// If a Logger is found in the context, it will be used.
func InfoContextf(ctx context.Context, format string, args ...any) {
wrapf(ctx, FromContext(ctx), slog.LevelInfo, format, args...)
}
// Warn calls Warn on the default logger.
func Warn(msg string, args ...any) {
wrap(context.Background(), DefaultLogger(), slog.LevelWarn, msg, args...)
}
// WarnContext calls WarnContext on the context logger.
// If a Logger is found in the context, it will be used.
func WarnContext(ctx context.Context, msg string, args ...any) {
wrap(ctx, FromContext(ctx), slog.LevelWarn, msg, args...)
}
// Warnf calls Warnf on the default logger.
func Warnf(format string, args ...any) {
wrapf(context.Background(), DefaultLogger(), slog.LevelWarn, format, args...)
}
// WarnContextf calls WarnContextf on the context logger.
// If a Logger is found in the context, it will be used.
func WarnContextf(ctx context.Context, format string, args ...any) {
wrapf(ctx, FromContext(ctx), slog.LevelWarn, format, args...)
}
// Error calls Error on the default logger.
func Error(msg string, args ...any) {
wrap(context.Background(), DefaultLogger(), slog.LevelError, msg, args...)
}
// ErrorContext calls ErrorContext on the context logger.
func ErrorContext(ctx context.Context, msg string, args ...any) {
wrap(ctx, FromContext(ctx), slog.LevelError, msg, args...)
}
// Errorf calls Errorf on the default logger.
func Errorf(format string, args ...any) {
wrapf(context.Background(), DefaultLogger(), slog.LevelError, format, args...)
}
// ErrorContextf calls ErrorContextf on the context logger.
func ErrorContextf(ctx context.Context, format string, args ...any) {
wrapf(ctx, FromContext(ctx), slog.LevelError, format, args...)
}
// Debug calls Debug on the default logger.
func Debug(msg string, args ...any) {
wrap(context.Background(), DefaultLogger(), slog.LevelDebug, msg, args...)
}
// DebugContext calls DebugContext on the context logger.
func DebugContext(ctx context.Context, msg string, args ...any) {
wrap(ctx, FromContext(ctx), slog.LevelDebug, msg, args...)
}
// Debugf calls Debugf on the default logger.
func Debugf(format string, args ...any) {
wrapf(context.Background(), DefaultLogger(), slog.LevelDebug, format, args...)
}
// DebugContextf calls DebugContextf on the context logger.
// If a Logger is found in the context, it will be used.
func DebugContextf(ctx context.Context, format string, args ...any) {
wrapf(ctx, FromContext(ctx), slog.LevelDebug, format, args...)
}