diff --git a/config/kis_func_config.go b/config/kis_func_config.go index 4f7f6b3..facb5d0 100644 --- a/config/kis_func_config.go +++ b/config/kis_func_config.go @@ -42,11 +42,11 @@ func NewFuncConfig( config.FName = funcName if source == nil { - log.Logger().ErrorF("funcName NewConfig Error, source is nil, funcName = %s\n", funcName) defaultSource := KisSource{ Name: "unNamedSource", } source = &defaultSource + log.Logger().InfoF("funcName NewConfig source is nil, funcName = %s, use default unNamed Source.\n", funcName) } config.Source = *source diff --git a/log/kis_default_log.go b/log/kis_default_log.go index 41e2ed3..94da4ee 100644 --- a/log/kis_default_log.go +++ b/log/kis_default_log.go @@ -3,10 +3,20 @@ package log import ( "context" "fmt" + "sync" ) // kisDefaultLog 默认提供的日志对象 -type kisDefaultLog struct{} +type kisDefaultLog struct { + debugMode bool + mu sync.Mutex +} + +func (log *kisDefaultLog) SetDebugMode(enable bool) { + log.mu.Lock() + defer log.mu.Unlock() + log.debugMode = enable +} func (log *kisDefaultLog) InfoF(str string, v ...interface{}) { fmt.Printf(str, v...) @@ -19,8 +29,12 @@ func (log *kisDefaultLog) ErrorF(str string, v ...interface{}) { } func (log *kisDefaultLog) DebugF(str string, v ...interface{}) { - fmt.Printf(str, v...) - fmt.Printf("\n") + log.mu.Lock() + defer log.mu.Unlock() + if log.debugMode { + fmt.Printf(str, v...) + fmt.Printf("\n") + } } func (log *kisDefaultLog) InfoFX(ctx context.Context, str string, v ...interface{}) { @@ -36,9 +50,13 @@ func (log *kisDefaultLog) ErrorFX(ctx context.Context, str string, v ...interfac } func (log *kisDefaultLog) DebugFX(ctx context.Context, str string, v ...interface{}) { - fmt.Println(ctx) - fmt.Printf(str, v...) - fmt.Printf("\n") + log.mu.Lock() + defer log.mu.Unlock() + if log.debugMode { + fmt.Println(ctx) + fmt.Printf(str, v...) + fmt.Printf("\n") + } } func init() { diff --git a/log/kis_log.go b/log/kis_log.go index 477e381..09fb761 100644 --- a/log/kis_log.go +++ b/log/kis_log.go @@ -16,6 +16,9 @@ type KisLogger interface { ErrorF(str string, v ...interface{}) // DebugF 无上下文的Debug级别日志接口, format字符串格式 DebugF(str string, v ...interface{}) + + // SetDebugMode 设置Debug模式 + SetDebugMode(enable bool) } // kisLog 默认的KisLog 对象, 提供默认的日志打印方式, 均是打印在标准输出上。