mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-21 12:14:45 +08:00
优化异常捕获日志
This commit is contained in:
@@ -180,16 +180,10 @@ func (slf *BaseMessageReciver) startReadMsg(pclient *WSClient) {
|
|||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
var coreInfo string
|
var coreInfo string
|
||||||
str, ok := r.(string)
|
coreInfo = string(debug.Stack())
|
||||||
if ok {
|
coreInfo += "\n" + fmt.Sprintf("Core information is %v\n", r)
|
||||||
coreInfo = string(debug.Stack())
|
|
||||||
} else {
|
|
||||||
coreInfo = "Panic!"
|
|
||||||
}
|
|
||||||
|
|
||||||
coreInfo += "\n" + fmt.Sprintf("core information is %s\n", str)
|
|
||||||
service.GetLogger().Printf(service.LEVER_FATAL, coreInfo)
|
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)
|
slf.WsServer.ReleaseClient(pclient)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
|
"github.com/duanhf2012/origin/util"
|
||||||
|
|
||||||
"net/http"
|
"net/http"
|
||||||
_ "net/http/pprof"
|
_ "net/http/pprof"
|
||||||
"os"
|
"os"
|
||||||
@@ -37,6 +39,7 @@ func (s *COriginNode) Init() {
|
|||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
util.Log = logger.Printf
|
||||||
s.sigs = make(chan os.Signal, 1)
|
s.sigs = make(chan os.Signal, 1)
|
||||||
signal.Notify(s.sigs, syscall.SIGINT, syscall.SIGTERM)
|
signal.Notify(s.sigs, syscall.SIGINT, syscall.SIGTERM)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -130,6 +130,7 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"encoding/gob"
|
"encoding/gob"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
@@ -396,14 +397,10 @@ func (s *service) call(server *Server, sending *sync.Mutex, wg *sync.WaitGroup,
|
|||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
var coreInfo string
|
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 += "\nCore Request RPC Name:" + req.ServiceMethod
|
||||||
|
coreInfo += "\n" + fmt.Sprintf("Core information is %v\n", r)
|
||||||
orginservice.GetLogger().Printf(orginservice.LEVER_FATAL, coreInfo)
|
orginservice.GetLogger().Printf(orginservice.LEVER_FATAL, coreInfo)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|||||||
@@ -218,12 +218,14 @@ func (slf *BaseModule) AddModule(module IModule) uint32 {
|
|||||||
slf.mapModule[module.GetModuleId()] = module
|
slf.mapModule[module.GetModuleId()] = module
|
||||||
|
|
||||||
//运行模块
|
//运行模块
|
||||||
|
GetLogger().Printf(LEVER_INFO, "Start Init module %T.", module)
|
||||||
err := module.OnInit()
|
err := module.OnInit()
|
||||||
if err != nil {
|
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)
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
module.getBaseModule().OnInit()
|
module.getBaseModule().OnInit()
|
||||||
|
GetLogger().Printf(LEVER_INFO, "End Init module %T.", module)
|
||||||
|
|
||||||
go module.RunModule(module)
|
go module.RunModule(module)
|
||||||
return module.GetModuleId()
|
return module.GetModuleId()
|
||||||
@@ -286,15 +288,12 @@ func (slf *BaseModule) RunModule(module IModule) {
|
|||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
var coreInfo string
|
var coreInfo string
|
||||||
str, ok := r.(string)
|
coreInfo = string(debug.Stack())
|
||||||
if ok {
|
|
||||||
coreInfo = string(debug.Stack())
|
coreInfo += "\n" + fmt.Sprintf("Core module is %T, try count %d. core information is %v\n", module, slf.recoverCount, r)
|
||||||
} else {
|
|
||||||
coreInfo = "Panic!"
|
|
||||||
}
|
|
||||||
coreInfo += "\n" + fmt.Sprintf("Core module is %T, try count %d. core information is %s\n", module, slf.recoverCount, str)
|
|
||||||
GetLogger().Printf(LEVER_FATAL, coreInfo)
|
GetLogger().Printf(LEVER_FATAL, coreInfo)
|
||||||
slf.recoverCount += 1
|
slf.recoverCount += 1
|
||||||
|
|
||||||
//重试3次
|
//重试3次
|
||||||
if slf.recoverCount < 4 {
|
if slf.recoverCount < 4 {
|
||||||
go slf.RunModule(slf.GetSelf())
|
go slf.RunModule(slf.GetSelf())
|
||||||
|
|||||||
@@ -60,12 +60,15 @@ func (slf *CServiceManager) Init(logger ILogger, exit chan bool, pwaitGroup *syn
|
|||||||
func (slf *CServiceManager) Start() bool {
|
func (slf *CServiceManager) Start() bool {
|
||||||
for _, sname := range slf.orderLocalService {
|
for _, sname := range slf.orderLocalService {
|
||||||
s := slf.FindService(sname)
|
s := slf.FindService(sname)
|
||||||
|
|
||||||
|
GetLogger().Printf(LEVER_INFO, "Start Init module %T.", s.(IModule))
|
||||||
err := s.(IModule).OnInit()
|
err := s.(IModule).OnInit()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
GetLogger().Printf(LEVER_ERROR, "Init module %T id is %d is fail,reason:%v...", s.(IModule), s.(IModule).GetModuleId(), err)
|
GetLogger().Printf(LEVER_ERROR, "Init module %T id is %d is fail,reason:%v...", s.(IModule), s.(IModule).GetModuleId(), err)
|
||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
s.(IModule).getBaseModule().OnInit()
|
s.(IModule).getBaseModule().OnInit()
|
||||||
|
GetLogger().Printf(LEVER_INFO, "End Init module %T.", s.(IModule))
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, sname := range slf.orderLocalService {
|
for _, sname := range slf.orderLocalService {
|
||||||
|
|||||||
@@ -10,14 +10,8 @@ func F(callback interface{}, args ...interface{}) {
|
|||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
var coreInfo string
|
var coreInfo string
|
||||||
str, ok := r.(string)
|
coreInfo = string(debug.Stack())
|
||||||
if ok {
|
coreInfo += "\n" + fmt.Sprintf("Core information is %v\n", r)
|
||||||
coreInfo = string(debug.Stack())
|
|
||||||
} else {
|
|
||||||
coreInfo = "Panic!"
|
|
||||||
}
|
|
||||||
|
|
||||||
coreInfo += "\n" + fmt.Sprintf("core information is %s\n", str)
|
|
||||||
if Log != nil {
|
if Log != nil {
|
||||||
Log(5, coreInfo)
|
Log(5, coreInfo)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user