From 75efec48bf7cccb43207ab29bd273500fb82fd01 Mon Sep 17 00:00:00 2001 From: Yun Date: Sat, 23 Aug 2025 19:17:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=9A=E5=8A=A1=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- interfaces.go | 11 +++++++++++ loggerx.go | 18 ++++++++++++++++++ options.go | 2 ++ 3 files changed, 31 insertions(+) diff --git a/interfaces.go b/interfaces.go index ef0f8ec..7132de5 100644 --- a/interfaces.go +++ b/interfaces.go @@ -9,3 +9,14 @@ type LoggerInterface interface { Error(ctx context.Context, args ...any) Errorf(ctx context.Context, format string, args ...any) } + +// Debug 使用的日志接口 +// Waring 警告的日志接口 + +type DebugLoggerInterface interface { + LoggerInterface + Debug(ctx context.Context, args ...any) + Debugf(ctx context.Context, format string, args ...any) + Warn(ctx context.Context, args ...any) + Warnf(ctx context.Context, format string, args ...any) +} \ No newline at end of file diff --git a/loggerx.go b/loggerx.go index 8e3c925..bc61948 100644 --- a/loggerx.go +++ b/loggerx.go @@ -129,6 +129,24 @@ func (l *Logger) Errorf(ctx context.Context, format string, v ...any) { l.logger(ctx, "error", s) } +func (l *Logger) Debug(ctx context.Context, v ...any) { + l.logger(ctx, "debug", v...) +} + +func (l *Logger) Debugf(ctx context.Context, format string, v ...any) { + s := fmt.Sprintf(format, v...) + l.logger(ctx, "debug", s) +} + +func (l *Logger) Warn(ctx context.Context, v ...any) { + l.logger(ctx, "warn", v...) +} + +func (l *Logger) Warnf(ctx context.Context, format string, v ...any) { + s := fmt.Sprintf(format, v...) + l.logger(ctx, "warn", s) +} + // 添加固定的内容 // func (l *Logger) ContextWithFields(ctx context.Context, v ...any) { // l.logger(ctx, "add", v...) diff --git a/options.go b/options.go index 6b72605..e91f929 100644 --- a/options.go +++ b/options.go @@ -60,6 +60,8 @@ func SetTraceField(traceField string) Option { } } +// 1.info 2.error 3.debug 4.warn 5.fatal + // 附加字段 func SetExpandData(key string, value string) Option { return func(o *loggerOption) {