| | |
| | | |
| | | 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) |
| | | |
| | |
| | | if nil == log { |
| | | return |
| | | } |
| | | |
| | | log.ProcName = ProcName |
| | | log.ProcID = ProcID |
| | | |
| | | select { |
| | | case opChan <- log: |
| | |
| | | } |
| | | } |
| | | |
| | | 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) |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | Timestamp int64 `gorm:"column:timestamp" json:"timestamp"` // 时间戳Unix 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"` // 参数 |
| New file |
| | |
| | | package logc |
| | | |
| | | type ScheduleLog struct { |
| | | ID string `gorm:"column:id;primaryKey;unique;autoIncrement" json:"id"` // 主键id |
| | | Timestamp int64 `gorm:"column:timestamp" json:"timestamp"` // 时间戳Unix 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"` // 详情 |
| | | } |