添加数据log记录

This commit is contained in:
lyp-home 2019-05-28 22:38:12 +08:00
parent 69c9c2d829
commit cce6ad6489
4 changed files with 27 additions and 4 deletions

View File

@ -225,5 +225,6 @@
"api_port":10086,
"pro_category":1,
"syn_data":false,
"syn_extension_Time":false
"syn_extension_Time":false,
"record_log_path":"/usr/local/dpark"
}

View File

@ -42,6 +42,7 @@ type Conf struct {
PROCATEGORY int `json:"pro_category"`
SYNDATA bool `json:"syn_data"`
SYNEXTENSIONTIME bool `json:"syn_extension_Time"`
RECORD_LOG_PATH string `json:"record_log_path"`
}
//无线 下位机
@ -99,7 +100,7 @@ var conf Conf
var DEVICEDATAS Devicedatas
var demoDevice Device
var today string
//var airDevice Device
//var femaledemoDevice Device
@ -113,7 +114,10 @@ var loraNodeMap sync.Map
// 加载配置文件
func init() {
time.Now()
t := time.Now()
today = t.Format("2006-01-02")
configfile, err := os.Open("conf/gateway.conf")
check(err)

View File

@ -225,7 +225,7 @@ func readConn(conn net.Conn, readChan chan<- []byte, stopChan chan<- bool) {
buffer = new(bytes.Buffer)
go record_log(data[i-4:i+end])
// if(dataType ==1 || dataType ==2 || dataType == 4 ){
go dealDatav3(data[i-4:i+end])
// }

View File

@ -4,6 +4,7 @@ import (
"encoding/binary"
"github.com/tarm/serial"
"log"
"os"
_ "math/rand"
"strconv"
"sync"
@ -76,6 +77,23 @@ func yunhorn_xdy_l_v1(data_buf []byte) {
}
func record_log(data_buf []byte){
time := today
folder := conf.RECORD_LOG_PATH+"/"+time
err2 :=os.MkdirAll(folder,os.ModePerm)
if err2!=nil{
log.Println(err2)
}
f, err := os.OpenFile(folder+"/"+time, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
if err != nil{
log.Fatalln("HHHHH")
}
record := log.New(f,"",log.Llongfile)
//debugLog.SetPrefix("[Debug]")
record.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
record.Println(data_buf)
}
func yunhorn_lora_l_v1(data_buf []byte) {
// for _, i := range conf.RS485DEVICES {