Skip to content

Commit

Permalink
using ibbd-dev/go-async-log realizes log cutting
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas7788 committed Oct 20, 2017
1 parent 84eefd7 commit 9daeb54
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 78 deletions.
Binary file removed ad_server
Binary file not shown.
6 changes: 0 additions & 6 deletions log/click/click.log.201710201700

This file was deleted.

1 change: 1 addition & 0 deletions log/click/click.log.2017102019
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2017-10-20T19:04:56+08:00 hello
3 changes: 0 additions & 3 deletions log/impression/impression.log.201710201600

This file was deleted.

2 changes: 2 additions & 0 deletions log/impression/impression.log.2017102019
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
2017-10-20T19:04:40+08:00 i am impression
2017-10-20T19:04:46+08:00 i am impression
27 changes: 8 additions & 19 deletions src/adhandler/click_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@ import (
//"math/rand"
"adserver"
"encoding/base64"
"github.com/sirupsen/logrus"
"time"
"github.com/ibbd-dev/go-async-log"
)
func ClickHandler(w http.ResponseWriter, r *http.Request) {
ConfigLocalFilesystemLogger("./log/click","click.log",time.Hour*24,time.Hour)
var logfileClick = asyncLog.NewLogFile("./log/click/click.log")
func ClickHandler(w http.ResponseWriter, r *http.Request) {

//获得编码后的查询字符串
queryStringEncoded := r.URL.RawQuery
//解码
queryStringDecodedBytes , err := base64.StdEncoding.DecodeString(queryStringEncoded)
if err != nil {//异常处理
adLog.Println(err)
if err != nil {
return
}
r.URL.RawQuery = string(queryStringDecodedBytes)
Expand Down Expand Up @@ -72,17 +70,8 @@ func ClickHandler(w http.ResponseWriter, r *http.Request) {
if len(r.Form["click_url"]) > 0 {
req.ClickUrl = r.Form["click_url"][0]
}
adLog.WithFields(logrus.Fields{
"appId": req.AppId,
"slotId": req.SlotId,
"adNum":req.AdNum,
"iP":req.Ip,
"deviceId":req.DeviceId,
"oS":req.Os,
"osVersion":req.OsVersion,
"unitId":req.UnitId,
"creativeId":req.CreativeId,
"searchId":req.SearchId,
"clickUrl":req.ClickUrl,
}).Info("test click")
err= logfileClick.Write("i am click")
if err!=nil{
return
}
}
30 changes: 12 additions & 18 deletions src/adhandler/impression_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,24 @@ import (
//"math/rand"
"adserver"
"encoding/base64"
"time"
"github.com/sirupsen/logrus"
"github.com/ibbd-dev/go-async-log"
)

/*
* ibbd-dev/go-async-log 日志框架说明
* 1. 自动切割周期:默认按小时
* 2. 默认全部写入文件
* 3. 批量写入周期:默认每秒写入一次
* 4. 是否需要Flags:默认需要
*/
var logfileImpression = asyncLog.NewLogFile("./log/impression/impression.log")
//展示handler
func ImpressionHandler(w http.ResponseWriter, r *http.Request) {
ConfigLocalFilesystemLogger("./log/impression","impression.log",time.Hour*24,time.Hour)

//获得编码后的查询字符串
queryStringEncoded := r.URL.RawQuery
//解码
queryStringDecodedBytes,err := base64.StdEncoding.DecodeString(queryStringEncoded)
if err != nil{//异常处理
adLog.Println(err)
if err != nil{
return
}
r.URL.RawQuery = string(queryStringDecodedBytes)
Expand Down Expand Up @@ -68,16 +73,5 @@ func ImpressionHandler(w http.ResponseWriter, r *http.Request) {
if len(r.Form["search_id"]) > 0 {
req.SearchId = r.Form["search_id"][0]
}
adLog.WithFields(logrus.Fields{
"appId": req.AppId,
"slotId": req.SlotId,
"adNum":req.AdNum,
"iP":req.Ip,
"deviceId":req.DeviceId,
"oS":req.Os,
"osVersion":req.OsVersion,
"unitId":req.UnitId,
"creativeId":req.CreativeId,
"searchId":req.SearchId,
}).Info("test displayHandler")
logfileImpression.Write("i am impression")
}
32 changes: 0 additions & 32 deletions src/adhandler/init_log.go

This file was deleted.

0 comments on commit 9daeb54

Please sign in to comment.