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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
package clog
import (
"context"
"log/slog"
"os"
)
// 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...)
}
// Fatal calls Error on the default logger, then exits.
func Fatal(msg string, args ...any) {
wrap(context.Background(), DefaultLogger(), slog.LevelError, msg, args...)
os.Exit(1)
}
// FatalContext calls ErrorContext on the context logger, then exits.
func FatalContext(ctx context.Context, msg string, args ...any) {
wrap(ctx, FromContext(ctx), slog.LevelError, msg, args...)
os.Exit(1)
}
// Fatalf calls Errorf on the default logger, then exits.
func Fatalf(format string, args ...any) {
wrapf(context.Background(), DefaultLogger(), slog.LevelError, format, args...)
os.Exit(1)
}
// FatalContextf calls ErrorContextf on the context logger, then exits.
func FatalContextf(ctx context.Context, format string, args ...any) {
wrapf(ctx, FromContext(ctx), slog.LevelError, format, args...)
os.Exit(1)
}
|