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