diff --git a/logger/drivers/dummyLogger.go b/logger/drivers/dummyLogger.go new file mode 100644 index 0000000..ccfed19 --- /dev/null +++ b/logger/drivers/dummyLogger.go @@ -0,0 +1,27 @@ +package drivers + +type DummyLogger struct{} + +func (l *DummyLogger) Debug(msg string, v ...interface{}) {} + +func (l *DummyLogger) Info(msg string, v ...interface{}) {} + +func (l *DummyLogger) Warn(msg string, v ...interface{}) {} + +func (l *DummyLogger) Error(msg string, v ...interface{}) {} + +func (l *DummyLogger) Panic(msg string, v ...interface{}) {} + +func (l *DummyLogger) Fatal(msg string, v ...interface{}) {} + +func (l *DummyLogger) DebugF(format string, args ...interface{}) {} + +func (l *DummyLogger) InfoF(format string, args ...interface{}) {} + +func (l *DummyLogger) WarnF(format string, args ...interface{}) {} + +func (l *DummyLogger) ErrorF(format string, args ...interface{}) {} + +func (l *DummyLogger) PanicF(format string, args ...interface{}) {} + +func (l *DummyLogger) FatalF(format string, args ...interface{}) {} diff --git a/logger/drivers/simpleLogger.go b/logger/drivers/simpleLogger.go new file mode 100644 index 0000000..a25c456 --- /dev/null +++ b/logger/drivers/simpleLogger.go @@ -0,0 +1,65 @@ +package drivers + +import ( + "fmt" + "log" +) + +const ( + DebugLevel int8 = 0 + InfoLevel int8 = 1 + WarningLevel int8 = 2 + ErrorLevel int8 = 3 + PanicLevel int8 = 4 + FatalLevel int8 = 5 +) + +type SimpleLogger struct{} + +func (l *SimpleLogger) Debug(msg string, v ...interface{}) { + log.Printf("[DEBUG] "+msg, v...) +} + +func (l *SimpleLogger) Info(msg string, v ...interface{}) { + log.Printf("[INFO] "+msg, v...) +} + +func (l *SimpleLogger) Warn(msg string, v ...interface{}) { + log.Printf("[WARNING] "+msg, v...) +} + +func (l *SimpleLogger) Error(msg string, v ...interface{}) { + log.Printf("[ERROR] "+msg, v...) +} + +func (l *SimpleLogger) Panic(msg string, v ...interface{}) { + log.Panicf("[PANIC] "+msg, v...) +} + +func (l *SimpleLogger) Fatal(msg string, v ...interface{}) { + log.Fatalf("[FATAL] "+msg, v...) +} + +func (l *SimpleLogger) DebugF(format string, args ...interface{}) { + l.Debug(fmt.Sprintf(format, args...)) +} + +func (l *SimpleLogger) InfoF(format string, args ...interface{}) { + l.Info(fmt.Sprintf(format, args...)) +} + +func (l *SimpleLogger) WarnF(format string, args ...interface{}) { + l.Warn(fmt.Sprintf(format, args...)) +} + +func (l *SimpleLogger) ErrorF(format string, args ...interface{}) { + l.Error(fmt.Sprintf(format, args...)) +} + +func (l *SimpleLogger) PanicF(format string, args ...interface{}) { + l.Panic(fmt.Sprintf(format, args...)) +} + +func (l *SimpleLogger) FatalF(format string, args ...interface{}) { + l.Fatal(fmt.Sprintf(format, args...)) +} diff --git a/logger/drivers/zap/log.go b/logger/drivers/zap/log.go index 52f08ae..fed711e 100644 --- a/logger/drivers/zap/log.go +++ b/logger/drivers/zap/log.go @@ -96,11 +96,6 @@ func newZapLogger(config *object.HashMap) (logger *zap.Logger, err error) { //fmt.Dump(level, ok) if ok { switch level { - case "off": - // 将日志级别设置为zapcore.Level(-1),相当于关闭日志输出 - infoLevel = zap.LevelEnablerFunc(func(lvl zapcore.Level) bool { - return false // 禁用所有日志 - }) case "debug": infoLevel = zap.LevelEnablerFunc(func(lvl zapcore.Level) bool { return lvl < zapcore.ErrorLevel