mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-04 06:54:45 +08:00
优化日志服务增加前缀以及取消日志的日期目录
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
"SubNet1_Service",
|
||||
"SubNet1_Service1"
|
||||
],
|
||||
"ClusterNode":["SubNet2.N_Node1"]
|
||||
"ClusterNode":["SubNet2.N_Node1","N_Node2"]
|
||||
},
|
||||
{
|
||||
"NodeID": 2,
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"math/rand"
|
||||
"net"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -192,29 +191,9 @@ func (slf *CCluster) ConnService() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (slf *CCluster) Init() error {
|
||||
if len(os.Args) < 2 {
|
||||
return fmt.Errorf("Param error not find NodeId=number")
|
||||
}
|
||||
|
||||
parts := strings.Split(os.Args[1], "=")
|
||||
if len(parts) < 2 {
|
||||
return fmt.Errorf("Param error not find NodeId=number")
|
||||
}
|
||||
|
||||
if parts[0] != "NodeId" {
|
||||
|
||||
return fmt.Errorf("Param error not find NodeId=number")
|
||||
}
|
||||
|
||||
func (slf *CCluster) Init(currentNodeid int) error {
|
||||
slf.nodeclient = make(map[int]*RpcClient)
|
||||
|
||||
//读取配置
|
||||
currentNodeid, err := strconv.Atoi(parts[1])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return slf.ReadNodeInfo(currentNodeid)
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ package originnode
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/duanhf2012/origin/util"
|
||||
|
||||
@@ -101,7 +103,38 @@ func (s *COriginNode) Stop() {
|
||||
s.waitGroup.Wait()
|
||||
}
|
||||
|
||||
func GetCmdParamNodeId() int {
|
||||
if len(os.Args) < 2 {
|
||||
return 0
|
||||
//return fmt.Errorf("Param error not find NodeId=number")
|
||||
}
|
||||
|
||||
parts := strings.Split(os.Args[1], "=")
|
||||
if len(parts) < 2 {
|
||||
return 0
|
||||
//return fmt.Errorf("Param error not find NodeId=number")
|
||||
}
|
||||
|
||||
if parts[0] != "NodeId" {
|
||||
return 0
|
||||
//return fmt.Errorf("Param error not find NodeId=number")
|
||||
}
|
||||
|
||||
//读取配置
|
||||
currentNodeid, err := strconv.Atoi(parts[1])
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
return currentNodeid
|
||||
}
|
||||
|
||||
func NewOriginNode() *COriginNode {
|
||||
CurrentNodeId := GetCmdParamNodeId()
|
||||
if CurrentNodeId == 0 {
|
||||
fmt.Print("Param error not find NodeId=number")
|
||||
os.Exit(-1)
|
||||
}
|
||||
|
||||
//创建模块
|
||||
node := new(COriginNode)
|
||||
@@ -110,12 +143,11 @@ func NewOriginNode() *COriginNode {
|
||||
|
||||
//安装系统服务
|
||||
syslogservice := &sysservice.LogService{}
|
||||
syslogservice.InitLog("syslog", sysmodule.LEVER_INFO)
|
||||
|
||||
syslogservice.InitLog("syslog", fmt.Sprintf("syslog_%d", CurrentNodeId), sysmodule.LEVER_INFO)
|
||||
service.InstanceServiceMgr().Setup(syslogservice)
|
||||
|
||||
//初始化集群对象
|
||||
err := cluster.InstanceClusterMgr().Init()
|
||||
err := cluster.InstanceClusterMgr().Init(CurrentNodeId)
|
||||
if err != nil {
|
||||
fmt.Print(err)
|
||||
os.Exit(-1)
|
||||
|
||||
@@ -53,7 +53,7 @@ type LogModule struct {
|
||||
|
||||
func (slf *LogModule) GetCurrentFileName() string {
|
||||
now := time.Now()
|
||||
fpath := filepath.Join("logs", now.Format("2006-01-02"))
|
||||
fpath := filepath.Join("logs")
|
||||
os.MkdirAll(fpath, os.ModePerm)
|
||||
fname := slf.logfilename + "-" + now.Format("20060102-150405") + ".log"
|
||||
ret := filepath.Join(fpath, fname)
|
||||
@@ -100,9 +100,9 @@ func (slf *LogModule) CheckAndGenFile(fileline string) (newFile bool) {
|
||||
return newFile
|
||||
}
|
||||
|
||||
func (slf *LogModule) Init(logfilename string, openLevel uint) {
|
||||
func (slf *LogModule) Init(logFilePrefixName string, openLevel uint) {
|
||||
slf.currentDay = 0
|
||||
slf.logfilename = logfilename
|
||||
slf.logfilename = logFilePrefixName
|
||||
slf.openLevel = openLevel
|
||||
slf.calldepth = 3
|
||||
}
|
||||
|
||||
@@ -10,10 +10,10 @@ type LogService struct {
|
||||
logmodule *sysmodule.LogModule
|
||||
}
|
||||
|
||||
func (slf *LogService) InitLog(logservicename string, openLevel uint) {
|
||||
func (slf *LogService) InitLog(logservicename string, logFilePrefix string, openLevel uint) {
|
||||
slf.SetServiceName(logservicename)
|
||||
slf.logmodule = &sysmodule.LogModule{}
|
||||
slf.logmodule.Init(logservicename, openLevel)
|
||||
slf.logmodule.Init(logFilePrefix, openLevel)
|
||||
}
|
||||
|
||||
func (slf *LogService) Printf(level uint, format string, v ...interface{}) {
|
||||
|
||||
Reference in New Issue
Block a user