From 5413b950ac6693e24ac1cd7d8974ab8aa270b644 Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@smartai.com>
Date: 星期六, 22 一月 2022 12:04:44 +0800
Subject: [PATCH] 添加系统日志结构
---
logc.go | 56 ++++++++++++++--------------
scheduleLog.go | 22 +++++-----
vaSystemLog.go | 21 ++++++++++
operationlog.go | 18 ++++-----
4 files changed, 68 insertions(+), 49 deletions(-)
diff --git a/logc.go b/logc.go
index 7ae7c50..515dfc2 100644
--- a/logc.go
+++ b/logc.go
@@ -16,20 +16,19 @@
)
const (
- TypeManual = iota + 1 //浜哄伐鎿嶄綔鏃ュ織,绯荤粺鍗囩骇,鎽勫儚鏈轰慨鏀�,绠楁硶淇敼...
- TypeLoginOut //鐧诲綍鐧诲嚭鏃ュ織
- TypePollInfo //杞贰鎽勫儚鏈哄強鍏跺搴旂殑绠楁硶
- TypeStackInfo //鏁版嵁鏍堝鐞嗘儏鍐�
- TypeWarnInfo //鏁呴殰淇℃伅
- TypeRunInfo //杩愯鎯呭喌,gpu,mem,cpu
- TypeSysInfo //绯荤粺鍙傛暟鍙樻洿,ip,server name,寮�鍏虫満淇℃伅
+ TypeManual = iota + 1 //浜哄伐鎿嶄綔鏃ュ織,绯荤粺鍗囩骇,鎽勫儚鏈轰慨鏀�,绠楁硶淇敼...
+ TypeLoginOut //鐧诲綍鐧诲嚭鏃ュ織
+ TypePollInfo //杞贰鎽勫儚鏈哄強鍏跺搴旂殑绠楁硶
+ TypeStackInfo //鏁版嵁鏍堝鐞嗘儏鍐�
+ TypeWarnInfo //鏁呴殰淇℃伅
+ TypeRunInfo //杩愯鎯呭喌,gpu,mem,cpu
+ TypeSysInfo //绯荤粺鍙傛暟鍙樻洿,ip,server name,寮�鍏虫満淇℃伅
)
type LogPrinter interface {
Marshal() ([]byte, error)
Topic() string
}
-
type LogInfo struct {
ID string `gorm:"column:id;primary_key;unique" json:"id"`
@@ -44,21 +43,21 @@
}
type LogRegister struct {
- Nodes []bhome_msg.BHAddress
- Topic string
- Payload []byte
+ Nodes []bhome_msg.BHAddress
+ Topic string
+ Payload []byte
}
type LogReportCallback func(*LogRegister)
var (
- logCh chan LogPrinter
- logger *Log
+ logCh chan LogPrinter
+ logger *Log
ProcName string
- ProcID string
+ ProcID string
)
-func Init(flogWriter LogReportCallback, log *Log, procId string, procName string, wg *sync.WaitGroup, done chan struct{}) bool {
+func Init(flogWriter LogReportCallback, log *Log, procId string, procName string, wg *sync.WaitGroup, done chan struct{}) bool {
logCh = make(chan LogPrinter, 300)
if nil != log {
@@ -164,12 +163,13 @@
//}
const (
- OperationLogTopic = "operationLogSaveTopic"
- ScheduleLogTopic = "scheduleLogSaveTopic"
+ OperationLogTopic = "operationLogSaveTopic"
+ ScheduleLogTopic = "scheduleLogSaveTopic"
RuleServerLogTopic = "ruleServerLogSaveTopic"
+ VaSystemLogTopic = "VaSystemLogSaveTopic"
)
-func saveLoop(logCallback LogReportCallback, wg *sync.WaitGroup, done chan struct{}) {
+func saveLoop(logCallback LogReportCallback, wg *sync.WaitGroup, done chan struct{}) {
defer wg.Done()
if nil == logCallback {
@@ -178,23 +178,23 @@
for {
select {
- case <- done:
+ case <-done:
return
- case log := <- logCh:
+ case log := <-logCh:
payload, err := log.Marshal()
if err != nil {
logger.Error("failed to Marshal", log)
} else {
- var nodes []bhome_msg.BHAddress
- nodes = append(nodes, bhome_msg.BHAddress{})
+ var nodes []bhome_msg.BHAddress
+ nodes = append(nodes, bhome_msg.BHAddress{})
- reg := &LogRegister {
- nodes,
- log.Topic(),
- payload,
- }
+ reg := &LogRegister{
+ nodes,
+ log.Topic(),
+ payload,
+ }
- logCallback(reg)
+ logCallback(reg)
}
}
}
diff --git a/operationlog.go b/operationlog.go
index 980a9d0..5dd9cc9 100644
--- a/operationlog.go
+++ b/operationlog.go
@@ -9,20 +9,18 @@
Module string `gorm:"column:module" json:"module"` // 妯″潡
ProcName string `gorm:"column:procName" json:"procName"`
ProcID string `gorm:"column:procID" json:"procID"`
- Function string `gorm:"column:function" json:"function"` // 鍔熻兘
- Result string `gorm:"column:result" json:"result"` // 鎿嶄綔缁撴灉
- Para string `gorm:"column:para" json:"para"` // 鍙傛暟
- Msg string `gorm:"column:msg" json:"msg"` // 閿欒娑堟伅
- Ip string `gorm:"column:ip" json:"ip"` // 璇︽儏
- AddTime string `gorm:"column:add_time" json:"add_time"` // 璇︽儏
+ Function string `gorm:"column:function" json:"function"` // 鍔熻兘
+ Result string `gorm:"column:result" json:"result"` // 鎿嶄綔缁撴灉
+ Para string `gorm:"column:para" json:"para"` // 鍙傛暟
+ Msg string `gorm:"column:msg" json:"msg"` // 閿欒娑堟伅
+ Ip string `gorm:"column:ip" json:"ip"` // 璇︽儏
+ AddTime string `gorm:"column:add_time" json:"add_time"` // 璇︽儏
}
-func (l * OperationLog)Marshal()([]byte, error) {
+func (l *OperationLog) Marshal() ([]byte, error) {
return json.Marshal(l)
}
-func (l * OperationLog)Topic() string {
+func (l *OperationLog) Topic() string {
return OperationLogTopic
}
-
-
diff --git a/scheduleLog.go b/scheduleLog.go
index f7e6827..db5970f 100644
--- a/scheduleLog.go
+++ b/scheduleLog.go
@@ -3,21 +3,21 @@
import "encoding/json"
type ScheduleLog struct {
- ID string `gorm:"column:id;primaryKey;unique;autoIncrement" json:"id"` // 涓婚敭id
- Timestamp int64 `gorm:"column:timestamp" json:"timestamp"` // 鏃堕棿鎴砋nix time
- ProcName string `gorm:"column:procName" json:"procName"`
- ProcID string `gorm:"column:procID" json:"procID"`
- Level int `gorm:"column:level" json:"level"` // 鏃ュ織绛夌骇
- Type int `gorm:"column:type" json:"type"` // 鎿嶄綔绫诲瀷:浜哄伐鎿嶄綔,鐧诲綍閫�鍑�,杞惊鎽勫儚鏈哄強瀵瑰簲绠楁硶,鏁版嵁鏍堝鐞嗘儏鍐�,寮傚父鎯呭喌绛�
- Info string `gorm:"column:info" json:"info"` // 璇︽儏
- ScheduleStartTime string `gorm:"column:schedule_start_time" json:"schedule_start_time"` // 鏃堕棿鎴砋nix time
- ScheduleEndTime string `gorm:"column:schedule_end_time" json:"schedule_end_time"` // 鏃堕棿鎴砋nix time
+ ID string `gorm:"column:id;primaryKey;unique;autoIncrement" json:"id"` // 涓婚敭id
+ Timestamp int64 `gorm:"column:timestamp" json:"timestamp"` // 鏃堕棿鎴砋nix time
+ ProcName string `gorm:"column:procName" json:"procName"`
+ ProcID string `gorm:"column:procID" json:"procID"`
+ Level int `gorm:"column:level" json:"level"` // 鏃ュ織绛夌骇
+ Type int `gorm:"column:type" json:"type"` // 鎿嶄綔绫诲瀷:浜哄伐鎿嶄綔,鐧诲綍閫�鍑�,杞惊鎽勫儚鏈哄強瀵瑰簲绠楁硶,鏁版嵁鏍堝鐞嗘儏鍐�,寮傚父鎯呭喌绛�
+ Info string `gorm:"column:info" json:"info"` // 璇︽儏
+ ScheduleStartTime string `gorm:"column:schedule_start_time" json:"schedule_start_time"` // 鏃堕棿鎴砋nix time
+ ScheduleEndTime string `gorm:"column:schedule_end_time" json:"schedule_end_time"` // 鏃堕棿鎴砋nix time
}
-func (l * ScheduleLog)Marshal()([]byte, error) {
+func (l *ScheduleLog) Marshal() ([]byte, error) {
return json.Marshal(l)
}
-func (l * ScheduleLog)Topic() string {
+func (l *ScheduleLog) Topic() string {
return ScheduleLogTopic
}
diff --git a/vaSystemLog.go b/vaSystemLog.go
new file mode 100644
index 0000000..cf082d8
--- /dev/null
+++ b/vaSystemLog.go
@@ -0,0 +1,21 @@
+package logc
+
+import "encoding/json"
+
+type VaSystemLog struct {
+ ID string `gorm:"column:id;primaryKey;unique;autoIncrement" json:"id"` // 涓婚敭id
+ HostName string `gorm:"column:hostName" json:"hostName"` // 涓绘満鍚�
+ ProcName string `gorm:"column:procName" json:"procName"` // 杩涚▼鍚�
+ ProcID string `gorm:"column:procID" json:"procID"` // 杩涚▼pid
+ Level int `gorm:"column:level" json:"level"` // 鏃ュ織绛夌骇
+ Info string `gorm:"column:info" json:"info"` // 璇︽儏
+ Timestamp int64 `gorm:"column:timestamp" json:"timestamp"` // 鏃堕棿鎴砋nix time
+}
+
+func (v *VaSystemLog) Marshal() ([]byte, error) {
+ return json.Marshal(v)
+}
+
+func (v *VaSystemLog) Topic() string {
+ return VaSystemLogTopic
+}
--
Gitblit v1.8.0