| | |
| | | ) |
| | | |
| | | 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"` |
| | |
| | | } |
| | | |
| | | 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 { |
| | |
| | | //} |
| | | |
| | | 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 { |
| | |
| | | |
| | | 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) |
| | | } |
| | | } |
| | | } |
| | |
| | | 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 |
| | | } |
| | | |
| | | |
| | |
| | | import "encoding/json" |
| | | |
| | | 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"` // 详情 |
| | | ScheduleStartTime string `gorm:"column:schedule_start_time" json:"schedule_start_time"` // 时间戳Unix time |
| | | ScheduleEndTime string `gorm:"column:schedule_end_time" json:"schedule_end_time"` // 时间戳Unix time |
| | | 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"` // 详情 |
| | | ScheduleStartTime string `gorm:"column:schedule_start_time" json:"schedule_start_time"` // 时间戳Unix time |
| | | ScheduleEndTime string `gorm:"column:schedule_end_time" json:"schedule_end_time"` // 时间戳Unix 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 |
| | | } |
| New file |
| | |
| | | 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"` // 时间戳Unix time |
| | | } |
| | | |
| | | func (v *VaSystemLog) Marshal() ([]byte, error) { |
| | | return json.Marshal(v) |
| | | } |
| | | |
| | | func (v *VaSystemLog) Topic() string { |
| | | return VaSystemLogTopic |
| | | } |