2020-11-18 11:49:46 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
var oplog *Oplog
|
|
|
|
|
|
|
|
// Oplog 操作日志类
|
|
|
|
type Oplog struct {
|
|
|
|
oplog *log.Logger
|
|
|
|
}
|
|
|
|
|
|
|
|
func initOplog() {
|
|
|
|
if oplog == nil {
|
|
|
|
oplog = &Oplog{}
|
|
|
|
f, err := os.OpenFile("./op.log", os.O_CREATE|os.O_APPEND|os.O_RDWR, 0644)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
oplog.oplog = log.New(f, "", log.Lmsgprefix)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write 操作日志写入
|
|
|
|
func (op *Oplog) Write(data interface{}) {
|
|
|
|
if d, ok := data.(*Task); ok {
|
|
|
|
data, err := json.Marshal(d)
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
}
|
|
|
|
op.oplog.Println(string(data))
|
|
|
|
return
|
|
|
|
}
|
2020-11-19 07:32:43 +00:00
|
|
|
log.Println("data must Task: ", data)
|
2020-11-18 11:49:46 +00:00
|
|
|
}
|