mirror of
https://github.com/aceld/kis-flow.git
synced 2025-01-23 07:30:23 +08:00
Merge pull request #12 from aceld/feature/aceld
add logger SetDebugMode
This commit is contained in:
commit
ef62e6ce54
@ -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
|
||||
|
||||
|
@ -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() {
|
||||
|
@ -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 对象, 提供默认的日志打印方式, 均是打印在标准输出上。
|
||||
|
Loading…
Reference in New Issue
Block a user