mirror of
https://github.com/duanhf2012/origin.git
synced 2026-05-14 03:37:31 +08:00
对日志模块增加监听器
This commit is contained in:
@@ -135,13 +135,13 @@ func NewOrginNode() *COriginNode {
|
|||||||
return node
|
return node
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *COriginNode) SetLogLevel(level uint) {
|
func (s *COriginNode) GetSysLog() *sysservice.LogService {
|
||||||
logService := service.InstanceServiceMgr().FindService("syslog")
|
logService := service.InstanceServiceMgr().FindService("syslog")
|
||||||
if logService == nil {
|
if logService == nil {
|
||||||
fmt.Printf("Cannot find syslog service!")
|
fmt.Printf("Cannot find syslog service!")
|
||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
logService.(*sysservice.LogService).SetLogLevel(level)
|
|
||||||
|
|
||||||
|
return logService.(*sysservice.LogService)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ type ILogger interface {
|
|||||||
SetLogLevel(level uint)
|
SetLogLevel(level uint)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type FunListenLog func(uint, string)
|
||||||
|
|
||||||
type LogModule struct {
|
type LogModule struct {
|
||||||
service.BaseModule
|
service.BaseModule
|
||||||
currentDay int
|
currentDay int
|
||||||
@@ -38,6 +40,7 @@ type LogModule struct {
|
|||||||
openLevel uint
|
openLevel uint
|
||||||
locker sync.Mutex
|
locker sync.Mutex
|
||||||
calldepth int
|
calldepth int
|
||||||
|
listenFun FunListenLog
|
||||||
}
|
}
|
||||||
|
|
||||||
func (slf *LogModule) GetCurrentFileName() string {
|
func (slf *LogModule) GetCurrentFileName() string {
|
||||||
@@ -82,6 +85,10 @@ func (slf *LogModule) Init(logfilename string, openLevel uint) {
|
|||||||
slf.calldepth = 3
|
slf.calldepth = 3
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (slf *LogModule) SetListenLogFunc(listenFun FunListenLog) {
|
||||||
|
slf.listenFun = listenFun
|
||||||
|
}
|
||||||
|
|
||||||
func (slf *LogModule) GetLoggerByLevel(level uint) *log.Logger {
|
func (slf *LogModule) GetLoggerByLevel(level uint) *log.Logger {
|
||||||
if level >= LEVEL_MAX {
|
if level >= LEVEL_MAX {
|
||||||
level = 0
|
level = 0
|
||||||
@@ -94,8 +101,15 @@ func (slf *LogModule) Printf(level uint, format string, v ...interface{}) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if slf.openLevel == LEVER_DEBUG {
|
if slf.openLevel == LEVER_DEBUG || slf.listenFun != nil {
|
||||||
fmt.Println(LogPrefix[level], fmt.Sprintf(format, v...))
|
strlog := fmt.Sprintf(format, v...)
|
||||||
|
if slf.openLevel == LEVER_DEBUG {
|
||||||
|
fmt.Println(LogPrefix[level], strlog)
|
||||||
|
}
|
||||||
|
|
||||||
|
if slf.listenFun != nil {
|
||||||
|
slf.listenFun(level, fmt.Sprintf(format, v...))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
slf.CheckAndGenFile()
|
slf.CheckAndGenFile()
|
||||||
@@ -107,8 +121,15 @@ func (slf *LogModule) Print(level uint, v ...interface{}) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if slf.openLevel == LEVER_DEBUG {
|
if slf.openLevel == LEVER_DEBUG || slf.listenFun != nil {
|
||||||
fmt.Println(LogPrefix[level], fmt.Sprint(v...))
|
strlog := fmt.Sprint(v...)
|
||||||
|
if slf.openLevel == LEVER_DEBUG {
|
||||||
|
fmt.Println(LogPrefix[level], strlog)
|
||||||
|
}
|
||||||
|
|
||||||
|
if slf.listenFun != nil {
|
||||||
|
slf.listenFun(level, fmt.Sprint(v...))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
slf.CheckAndGenFile()
|
slf.CheckAndGenFile()
|
||||||
|
|||||||
@@ -31,3 +31,7 @@ func (slf *LogService) AppendCallDepth(calldepth int) {
|
|||||||
func (slf *LogService) SetLogLevel(level uint) {
|
func (slf *LogService) SetLogLevel(level uint) {
|
||||||
slf.logmodule.SetLogLevel(level)
|
slf.logmodule.SetLogLevel(level)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (slf *LogService) SetListenLogFunc(listenFun sysmodule.FunListenLog) {
|
||||||
|
slf.logmodule.SetListenLogFunc(listenFun)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user