From af04d69d231872447e0358aed8f848cf5bc1f93a Mon Sep 17 00:00:00 2001
From: yanghui <yanghui@aiotlink.com>
Date: 星期二, 27 四月 2021 13:37:42 +0800
Subject: [PATCH] add schedule log
---
logc.go | 41 +++++++++++++++++++++++++++++++++++++----
scheduleLog.go | 11 +++++++++++
operationlog.go | 2 ++
3 files changed, 50 insertions(+), 4 deletions(-)
diff --git a/logc.go b/logc.go
index f1fc460..5946d85 100644
--- a/logc.go
+++ b/logc.go
@@ -48,20 +48,24 @@
var (
opChan chan *OperationLog
+ schedualeChan chan *ScheduleLog
logger *Log
+ ProcName string
+ ProcID string
)
-
func Init(flogWriter LogReportCallback, log *Log, procId string, procName string, wg *sync.WaitGroup, done chan struct{}) bool {
opChan = make(chan *OperationLog, 100)
+ schedualeChan = make(chan *ScheduleLog)
+
if nil != log {
logger = log
} else {
logger = &Log{}
}
- //ProcName = procName
- //ProcID = procId
+ ProcName = procName
+ ProcID = procId
go saveLoop(flogWriter, wg, done)
@@ -72,6 +76,9 @@
if nil == log {
return
}
+
+ log.ProcName = ProcName
+ log.ProcID = ProcID
select {
case opChan <- log:
@@ -86,9 +93,35 @@
}
}
-func SaveScheduleLog(category, level int, timeout time.Duration, msg string) {
+func SaveScheduleLog(category, level int, timeout time.Duration, v ...interface{}) {
+ msg := ""
+ if len(v) > 0 {
+ msg = fmt.Sprint(v...)
+ }
+
if msg == "" {
+ retrun
+ }
+
+ log := &ScheduleLog{
+ Timestamp: time.Now().Unix(),
+ ProcName: ProcName,
+ ProcID: ProcID,
+ Level: level,
+ Type: category,
+ Info: msg,
+ }
+
+ select {
+ case schedualeChan <- log:
return
+ case <-time.After(timeout):
+ var info string
+ b, err := json.Marshal(log)
+ if nil == err {
+ info = string(b)
+ }
+ logger.Fatal("SaveScheduleLog failed to save log", info)
}
}
diff --git a/operationlog.go b/operationlog.go
index b6d8563..083e228 100644
--- a/operationlog.go
+++ b/operationlog.go
@@ -5,6 +5,8 @@
Timestamp int64 `gorm:"column:timestamp" json:"timestamp"` // 鏃堕棿鎴砋nix time
UserName string `gorm:"column:userName" json:"userName"` // 鐢ㄦ埛鍚嶅瓧
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"` // 鍙傛暟
diff --git a/scheduleLog.go b/scheduleLog.go
new file mode 100644
index 0000000..0cd045f
--- /dev/null
+++ b/scheduleLog.go
@@ -0,0 +1,11 @@
+package logc
+
+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"` // 璇︽儏
+}
--
Gitblit v1.8.0