日志屏幕输出

This commit is contained in:
boyce
2019-03-19 17:23:50 +08:00
parent 2c23d7fbd9
commit 7a215e6a83
5 changed files with 30 additions and 0 deletions

View File

@@ -130,3 +130,14 @@ func NewOrginNode() *COriginNode {
return node
}
func (s *COriginNode) SetLogLevel(level uint) {
logService := service.InstanceServiceMgr().FindService("syslog")
if logService == nil {
fmt.Printf("Cannot find syslog service!")
os.Exit(-1)
return
}
logService.(*sysservice.LogService).SetLogLevel(level)
}

View File

@@ -13,4 +13,5 @@ const (
type ILogger interface {
Printf(level uint, format string, v ...interface{})
Print(level uint, v ...interface{})
SetLogLevel(level uint)
}

View File

@@ -261,6 +261,7 @@ func (slf *BaseModule) RunModule(module IModule) {
if err != nil {
GetLogger().Printf(LEVER_ERROR, "Start module %T id is %d is fail,reason:%v...", module, module.GetModuleId(), err)
} else {
GetLogger().Printf(LEVER_INFO, "Start module %T ...", module)
}

View File

@@ -26,6 +26,7 @@ var LogPrefix = [LEVEL_MAX]string{"[UNKNOW]", "[DEBUG]", "[INFO ]", "[WARN ]", "
type ILogger interface {
Printf(level uint, format string, v ...interface{})
Print(level uint, v ...interface{})
SetLogLevel(level uint)
}
type LogModule struct {
@@ -93,6 +94,10 @@ func (slf *LogModule) Printf(level uint, format string, v ...interface{}) {
return
}
if slf.openLevel == LEVER_DEBUG {
fmt.Println(LogPrefix[level], fmt.Sprintf(format, v...))
}
slf.CheckAndGenFile()
slf.GetLoggerByLevel(level).Output(slf.calldepth, fmt.Sprintf(format, v...))
}
@@ -102,6 +107,10 @@ func (slf *LogModule) Print(level uint, v ...interface{}) {
return
}
if slf.openLevel == LEVER_DEBUG {
fmt.Println(LogPrefix[level], fmt.Sprint(v...))
}
slf.CheckAndGenFile()
slf.GetLoggerByLevel(level).Output(slf.calldepth, fmt.Sprint(v...))
}
@@ -109,3 +118,7 @@ func (slf *LogModule) Print(level uint, v ...interface{}) {
func (slf *LogModule) AppendCallDepth(calldepth int) {
slf.calldepth += calldepth
}
func (slf *LogModule) SetLogLevel(level uint) {
slf.openLevel = level
}

View File

@@ -27,3 +27,7 @@ func (slf *LogService) Print(level uint, v ...interface{}) {
func (slf *LogService) AppendCallDepth(calldepth int) {
slf.logmodule.AppendCallDepth(calldepth)
}
func (slf *LogService) SetLogLevel(level uint) {
slf.logmodule.SetLogLevel(level)
}