mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-27 07:16:19 +09:00
ci: add go lint and race test workflow (#187)
This commit is contained in:
@@ -10,8 +10,8 @@ import (
|
||||
type ctxKey struct{}
|
||||
|
||||
var (
|
||||
L *slog.Logger = slog.Default()
|
||||
logKey = ctxKey{}
|
||||
L = slog.Default()
|
||||
logKey = ctxKey{}
|
||||
)
|
||||
|
||||
// Init initializes the global logger with the given level and format (e.g. "debug", "json").
|
||||
@@ -60,7 +60,18 @@ func parseLevel(level string) slog.Level {
|
||||
}
|
||||
|
||||
// Debug, Info, Warn, Error log with the global logger (slog.Attr or key-value pairs).
|
||||
func Debug(msg string, args ...any) { L.Debug(msg, args...) }
|
||||
func Info(msg string, args ...any) { L.Info(msg, args...) }
|
||||
func Warn(msg string, args ...any) { L.Warn(msg, args...) }
|
||||
func Error(msg string, args ...any) { L.Error(msg, args...) }
|
||||
func Debug(msg string, args ...any) {
|
||||
L.Log(context.Background(), slog.LevelDebug, "global log", append([]any{slog.String("message", msg)}, args...)...)
|
||||
}
|
||||
|
||||
func Info(msg string, args ...any) {
|
||||
L.Log(context.Background(), slog.LevelInfo, "global log", append([]any{slog.String("message", msg)}, args...)...)
|
||||
}
|
||||
|
||||
func Warn(msg string, args ...any) {
|
||||
L.Log(context.Background(), slog.LevelWarn, "global log", append([]any{slog.String("message", msg)}, args...)...)
|
||||
}
|
||||
|
||||
func Error(msg string, args ...any) {
|
||||
L.Log(context.Background(), slog.LevelError, "global log", append([]any{slog.String("message", msg)}, args...)...)
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ func TestContextLogger(t *testing.T) {
|
||||
|
||||
expectedKey := "request_id"
|
||||
expectedValue := "12345"
|
||||
customLogger := L.With(expectedKey, expectedValue)
|
||||
customLogger := L.With(slog.String(expectedKey, expectedValue))
|
||||
|
||||
ctx := WithContext(context.Background(), customLogger)
|
||||
extracted := FromContext(ctx)
|
||||
|
||||
Reference in New Issue
Block a user