对日志监听器新增文件名和行数

This commit is contained in:
boyce
2019-03-26 14:39:26 +08:00
parent e0ae07388f
commit b0156ce788
4 changed files with 29 additions and 3 deletions

View File

@@ -310,7 +310,7 @@ func (slf *CCluster) Go(bCast bool, NodeServiceMethod string, args interface{})
if nodeid == GetNodeId() {
iService := service.InstanceServiceMgr().FindService(serviceName)
if iService.IsInit() == false {
service.GetLogger().Printf(sysmodule.LEVER_ERROR, "CCluster.Call(%s): NodeId %d is not init.", NodeServiceMethod, nodeid)
service.GetLogger().Printf(sysmodule.LEVER_WARN, "CCluster.Call(%s): NodeId %d is not init.", NodeServiceMethod, nodeid)
return fmt.Errorf("CCluster.Call(%s): NodeId %d is not init.", NodeServiceMethod, nodeid)
}

View File

@@ -295,7 +295,7 @@ func (slf *BaseModule) RunModule(module IModule) {
slf.recoverCount += 1
//重试3次
if slf.recoverCount < 4 {
if slf.recoverCount < 10 {
go slf.RunModule(slf.GetSelf())
} else {
GetLogger().Printf(LEVER_FATAL, "Routine %T.OnRun has exited!", module)
@@ -333,6 +333,7 @@ func (slf *BaseModule) RunModule(module IModule) {
GetLogger().Printf(LEVER_INFO, "OnEndRun module %T...", module)
return
}
}
}

View File

@@ -60,7 +60,6 @@ func (slf *CServiceManager) Init(logger ILogger, exit chan bool, pwaitGroup *syn
func (slf *CServiceManager) Start() bool {
for _, sname := range slf.orderLocalService {
s := slf.FindService(sname)
GetLogger().Printf(LEVER_INFO, "Start Init module %T.", s.(IModule))
err := s.(IModule).OnInit()
if err != nil {
@@ -103,3 +102,13 @@ func InstanceServiceMgr() *CServiceManager {
func GetLogger() ILogger {
return InstanceServiceMgr().GetLogger()
}
func (slf *CServiceManager) IsFinishInit() bool {
for _, val := range slf.localserviceMap {
if val.IsInit() == false {
return false
}
}
return true
}

View File

@@ -4,6 +4,8 @@ import (
"fmt"
"log"
"os"
"runtime"
"strings"
"sync"
"time"
@@ -108,6 +110,20 @@ func (slf *LogModule) Printf(level uint, format string, v ...interface{}) {
}
if slf.listenFun != nil {
var file string
var line int
var ok bool
_, file, line, ok = runtime.Caller(1)
if !ok {
file = "???"
line = 0
}
parts := strings.Split(file, "/")
if len(parts) > 0 {
file = parts[len(parts)-1]
}
format = LogPrefix[level] + time.Now().Format("2006/1/2 15:04:05") + fmt.Sprintf(" %s:%d:", file, line) + format
slf.listenFun(level, fmt.Sprintf(format, v...))
}
}