|
@@ -1,12 +1,15 @@
|
|
|
package tools
|
|
|
|
|
|
import (
|
|
|
+ "encoding/json"
|
|
|
"log"
|
|
|
"net"
|
|
|
"net/http"
|
|
|
"strings"
|
|
|
"sync"
|
|
|
"time"
|
|
|
+ uc "ucbsutil"
|
|
|
+ ca "ucbsutil/cassandra"
|
|
|
)
|
|
|
|
|
|
//对map的同步
|
|
@@ -28,13 +31,23 @@ func init() {
|
|
|
//定时保存日志
|
|
|
func SaveLogTask() {
|
|
|
lock.Lock()
|
|
|
- if len(arr) >= 1 {
|
|
|
+ /*if len(arr) >= 1 {
|
|
|
tmp := arr
|
|
|
arr = make([]map[string]interface{}, 0)
|
|
|
go func() {
|
|
|
log.Println("timer..save..log", len(tmp))
|
|
|
MQFW.SaveBulk("log", tmp...)
|
|
|
}()
|
|
|
+ }*/
|
|
|
+ if len(arr) >= 1 {
|
|
|
+ tmp := arr
|
|
|
+ arr = make([]map[string]interface{}, 0)
|
|
|
+ go func() {
|
|
|
+ success := ca.SaveBatch("jy_openapi", tmp)
|
|
|
+ if success {
|
|
|
+ log.Println("timer..visit..log", len(tmp))
|
|
|
+ }
|
|
|
+ }()
|
|
|
}
|
|
|
lock.Unlock()
|
|
|
time.AfterFunc(1*time.Minute, SaveLogTask)
|
|
@@ -47,40 +60,50 @@ func AddLog(req *http.Request, username, msg string, code, apicount int) {
|
|
|
ref := req.Referer()
|
|
|
s_url := req.RequestURI
|
|
|
date := timeNow.Unix()
|
|
|
+ md, _ := json.Marshal(req.Form)
|
|
|
+ str := string(md)
|
|
|
logs := map[string]interface{}{
|
|
|
- "l_date": date,
|
|
|
- "s_ip": req.Proto,
|
|
|
- "s_refer": ref,
|
|
|
- "i_year": timeNow.Year(),
|
|
|
- "i_month": timeNow.Month(),
|
|
|
- "i_day": timeNow.Day(),
|
|
|
- "i_hour": timeNow.Hour(),
|
|
|
- "i_minutes": timeNow.Minute(),
|
|
|
- "s_describe": req.Form,
|
|
|
- "s_client": agent,
|
|
|
- "s_os": GetOS(agent),
|
|
|
- "s_browse": GetBrowse(agent),
|
|
|
- "s_method": req.Method,
|
|
|
- "s_url": s_url,
|
|
|
- "s_username": username,
|
|
|
- "s_keyword": req.FormValue("keyword"),
|
|
|
- "s_appid": req.FormValue("appid"),
|
|
|
- "s_rMsg": msg,
|
|
|
- "s_signature": req.FormValue("signature"),
|
|
|
- "s_action": req.FormValue("action"),
|
|
|
- "s_pagenum": req.FormValue("pagenum"),
|
|
|
- "s_timestamp": req.FormValue("timestamp"),
|
|
|
- "i_rCode": code,
|
|
|
- "i_apicount": apicount,
|
|
|
+ "id": uc.DayShortTime(),
|
|
|
+ "date": date,
|
|
|
+ "ip": req.Proto,
|
|
|
+ "refer": ref,
|
|
|
+ "year": timeNow.Year(),
|
|
|
+ "month": timeNow.Month(),
|
|
|
+ "day": timeNow.Day(),
|
|
|
+ "hour": timeNow.Hour(),
|
|
|
+ "minutes": timeNow.Minute(),
|
|
|
+ "mdescribe": str,
|
|
|
+ "client": agent,
|
|
|
+ "os": GetOS(agent),
|
|
|
+ "browse": GetBrowse(agent),
|
|
|
+ "method": req.Method,
|
|
|
+ "url": s_url,
|
|
|
+ "uname": username,
|
|
|
+ "keyword": req.FormValue("keyword"),
|
|
|
+ "appid": req.FormValue("appid"),
|
|
|
+ "rmsg": msg,
|
|
|
+ "signature": req.FormValue("signature"),
|
|
|
+ "action": req.FormValue("action"),
|
|
|
+ "pagenum": req.FormValue("pagenum"),
|
|
|
+ "timestamp": req.FormValue("timestamp"),
|
|
|
+ "rcode": code,
|
|
|
+ "apicount": apicount,
|
|
|
}
|
|
|
lock.Lock()
|
|
|
arr = append(arr, logs)
|
|
|
if len(arr) >= nc {
|
|
|
tmp := arr
|
|
|
arr = make([]map[string]interface{}, 0)
|
|
|
- go func() {
|
|
|
+ /*go func() {
|
|
|
log.Println("save..article..log", len(tmp))
|
|
|
MQFW.SaveBulk("log", tmp...)
|
|
|
+ }()*/
|
|
|
+
|
|
|
+ go func() {
|
|
|
+ success := ca.SaveBatch("jy_openapi", tmp)
|
|
|
+ if success {
|
|
|
+ log.Println("save..article..log", len(tmp))
|
|
|
+ }
|
|
|
}()
|
|
|
}
|
|
|
lock.Unlock()
|