Skip to content

Commit

Permalink
Merge pull request #111 from ArtisanCloud/develop
Browse files Browse the repository at this point in the history
feat(log): add dummyLogger
  • Loading branch information
Matrix-X authored Aug 11, 2024
2 parents adf9bf2 + c58edfb commit d02aa21
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 5 deletions.
27 changes: 27 additions & 0 deletions logger/drivers/dummyLogger.go
Original file line number Diff line number Diff line change
@@ -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{}) {}
65 changes: 65 additions & 0 deletions logger/drivers/simpleLogger.go
Original file line number Diff line number Diff line change
@@ -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...))
}
5 changes: 0 additions & 5 deletions logger/drivers/zap/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d02aa21

Please sign in to comment.