From 4823244207f309163fef06207c44edfdbe6cdd8a Mon Sep 17 00:00:00 2001 From: "inu (Lucas DEBOUTE)" Date: Wed, 6 Mar 2024 13:05:55 -0800 Subject: [PATCH] feat(logger) support formatting --- pkg/logger/logger.go | 3 +++ pkg/logger/logrus/logrus.go | 12 ++++++++++++ pkg/logger/zap/zap.go | 16 ++++++++++++++-- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/pkg/logger/logger.go b/pkg/logger/logger.go index a8c3e8f..641a990 100644 --- a/pkg/logger/logger.go +++ b/pkg/logger/logger.go @@ -3,6 +3,9 @@ package logger // Logger interface implementation type Logger interface { Info(...any) + Infof(string, ...any) Warn(...any) + Warnf(string, ...any) Error(...any) + Errorf(string, ...any) } diff --git a/pkg/logger/logrus/logrus.go b/pkg/logger/logrus/logrus.go index ffd003f..51ed2f5 100644 --- a/pkg/logger/logrus/logrus.go +++ b/pkg/logger/logrus/logrus.go @@ -17,10 +17,22 @@ func (l LogrusLogger) Info(v ...any) { l.logger.Info(v...) } +func (l LogrusLogger) Infof(format string, v ...any) { + l.logger.Infof(format, v...) +} + func (l LogrusLogger) Error(v ...any) { l.logger.Error(v...) } +func (l LogrusLogger) Errorf(format string, v ...any) { + l.logger.Errorf(format, v...) +} + func (l LogrusLogger) Warn(v ...any) { l.logger.Warn(v...) } + +func (l LogrusLogger) Warnf(format string, v ...any) { + l.logger.Warnf(format, v...) +} diff --git a/pkg/logger/zap/zap.go b/pkg/logger/zap/zap.go index 28bf7bb..812af9b 100644 --- a/pkg/logger/zap/zap.go +++ b/pkg/logger/zap/zap.go @@ -17,10 +17,22 @@ func (z ZapSugarLogger) Info(v ...any) { z.logger.Info(v) } +func (z ZapSugarLogger) Infof(format string, v ...any) { + z.logger.Infof(format, v...) +} + func (z ZapSugarLogger) Warn(v ...any) { - z.logger.Info(v) + z.logger.Warn(v) +} + +func (z ZapSugarLogger) Warnf(format string, v ...any) { + z.logger.Warnf(format, v...) } func (z ZapSugarLogger) Error(v ...any) { - z.logger.Info(v) + z.logger.Error(v) +} + +func (z ZapSugarLogger) Errorf(format string, v ...any) { + z.logger.Errorf(format, v...) }