diff --git a/network/websocketserver.go b/network/websocketserver.go index 114b31b..9506db6 100644 --- a/network/websocketserver.go +++ b/network/websocketserver.go @@ -180,16 +180,10 @@ func (slf *BaseMessageReciver) startReadMsg(pclient *WSClient) { defer func() { if r := recover(); r != nil { var coreInfo string - str, ok := r.(string) - if ok { - coreInfo = string(debug.Stack()) - } else { - coreInfo = "Panic!" - } - - coreInfo += "\n" + fmt.Sprintf("core information is %s\n", str) + coreInfo = string(debug.Stack()) + coreInfo += "\n" + fmt.Sprintf("Core information is %v\n", r) service.GetLogger().Printf(service.LEVER_FATAL, coreInfo) - slf.messageReciver.OnDisconnect(pclient.clientid, errors.New("core dump")) + slf.messageReciver.OnDisconnect(pclient.clientid, errors.New("Core dump")) slf.WsServer.ReleaseClient(pclient) } }() diff --git a/originnode/node.go b/originnode/node.go index 9734b6f..88b2243 100644 --- a/originnode/node.go +++ b/originnode/node.go @@ -4,6 +4,8 @@ import ( "fmt" "log" + "github.com/duanhf2012/origin/util" + "net/http" _ "net/http/pprof" "os" @@ -37,6 +39,7 @@ func (s *COriginNode) Init() { os.Exit(-1) } + util.Log = logger.Printf s.sigs = make(chan os.Signal, 1) signal.Notify(s.sigs, syscall.SIGINT, syscall.SIGTERM) } diff --git a/rpc/server.go b/rpc/server.go index d9b1d11..06e0ce3 100644 --- a/rpc/server.go +++ b/rpc/server.go @@ -130,6 +130,7 @@ import ( "bufio" "encoding/gob" "errors" + "fmt" "io" "log" "net" @@ -396,14 +397,10 @@ func (s *service) call(server *Server, sending *sync.Mutex, wg *sync.WaitGroup, defer func() { if r := recover(); r != nil { var coreInfo string - str, ok := r.(string) - if ok { - coreInfo += str + "\n" + string(runtimedebug.Stack()) - } else { - coreInfo = "Panic!" - } + coreInfo = string(runtimedebug.Stack()) coreInfo += "\nCore Request RPC Name:" + req.ServiceMethod + coreInfo += "\n" + fmt.Sprintf("Core information is %v\n", r) orginservice.GetLogger().Printf(orginservice.LEVER_FATAL, coreInfo) } }() diff --git a/service/Module.go b/service/Module.go index 5a06559..11cefe4 100644 --- a/service/Module.go +++ b/service/Module.go @@ -218,12 +218,14 @@ func (slf *BaseModule) AddModule(module IModule) uint32 { slf.mapModule[module.GetModuleId()] = module //运行模块 + GetLogger().Printf(LEVER_INFO, "Start Init module %T.", module) err := module.OnInit() if err != nil { - GetLogger().Printf(LEVER_ERROR, "Init module %T id is %d is fail,reason:%v...", module, module.GetModuleId(), err) + GetLogger().Printf(LEVER_ERROR, "End Init module %T id is %d is fail,reason:%v...", module, module.GetModuleId(), err) os.Exit(-1) } module.getBaseModule().OnInit() + GetLogger().Printf(LEVER_INFO, "End Init module %T.", module) go module.RunModule(module) return module.GetModuleId() @@ -286,15 +288,12 @@ func (slf *BaseModule) RunModule(module IModule) { defer func() { if r := recover(); r != nil { var coreInfo string - str, ok := r.(string) - if ok { - coreInfo = string(debug.Stack()) - } else { - coreInfo = "Panic!" - } - coreInfo += "\n" + fmt.Sprintf("Core module is %T, try count %d. core information is %s\n", module, slf.recoverCount, str) + coreInfo = string(debug.Stack()) + + coreInfo += "\n" + fmt.Sprintf("Core module is %T, try count %d. core information is %v\n", module, slf.recoverCount, r) GetLogger().Printf(LEVER_FATAL, coreInfo) slf.recoverCount += 1 + //重试3次 if slf.recoverCount < 4 { go slf.RunModule(slf.GetSelf()) diff --git a/service/servicemanager.go b/service/servicemanager.go index 12b03d3..1782d26 100644 --- a/service/servicemanager.go +++ b/service/servicemanager.go @@ -60,12 +60,15 @@ 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 { GetLogger().Printf(LEVER_ERROR, "Init module %T id is %d is fail,reason:%v...", s.(IModule), s.(IModule).GetModuleId(), err) os.Exit(-1) } s.(IModule).getBaseModule().OnInit() + GetLogger().Printf(LEVER_INFO, "End Init module %T.", s.(IModule)) } for _, sname := range slf.orderLocalService { diff --git a/util/Coroutine.go b/util/Coroutine.go index c70ead1..0858fe1 100644 --- a/util/Coroutine.go +++ b/util/Coroutine.go @@ -10,14 +10,8 @@ func F(callback interface{}, args ...interface{}) { defer func() { if r := recover(); r != nil { var coreInfo string - str, ok := r.(string) - if ok { - coreInfo = string(debug.Stack()) - } else { - coreInfo = "Panic!" - } - - coreInfo += "\n" + fmt.Sprintf("core information is %s\n", str) + coreInfo = string(debug.Stack()) + coreInfo += "\n" + fmt.Sprintf("Core information is %v\n", r) if Log != nil { Log(5, coreInfo) } else {