forked from Gitlink/gitea-1120-rc1
fix log output
This commit is contained in:
parent
19545f4cee
commit
14df1f03fc
|
@ -75,18 +75,22 @@ func CompareCommitAndBranch(ctx *context.Context, repo *models.Repository, oldGr
|
||||||
|
|
||||||
if newGraphLen > oldGraphLen {
|
if newGraphLen > oldGraphLen {
|
||||||
str := StringfyGraph(CompareGraph(newGraph, oldGraph))
|
str := StringfyGraph(CompareGraph(newGraph, oldGraph))
|
||||||
logTemplate := LogTemplate{
|
//logTemplate := LogTemplate{
|
||||||
login: " "+identity,
|
// login: " "+identity,
|
||||||
time: " "+time.Now().Format("2006-01-02 15:04:05 -0700"),
|
// time: " "+time.Now().Format("2006-01-02 15:04:05 -0700"),
|
||||||
method: " "+ctx.Req.Method,
|
// method: " "+ctx.Req.Method,
|
||||||
uri: " "+ctx.Req.URL.RequestURI(),
|
// uri: " "+ctx.Req.URL.RequestURI(),
|
||||||
proto: " "+ctx.Req.Proto,
|
// proto: " "+ctx.Req.Proto,
|
||||||
response_code: " -",
|
// response_code: " -",
|
||||||
agent: " "+ctx.Req.UserAgent(),
|
// agent: " "+ctx.Req.UserAgent(),
|
||||||
request_body: " "+str,
|
// request_body: " "+str,
|
||||||
}
|
//}
|
||||||
|
logTemplate := fmt.Sprintf(
|
||||||
|
"{login: %s, time: %s, method: %s, uri: %s, proto: %s, response_code: -, agent: %s, request_body: %s}",
|
||||||
|
identity, time.Now().Format("2006-01-02 15:04:05 -0700"), ctx.Req.Method,
|
||||||
|
ctx.Req.URL.RequestURI(), ctx.Req.Proto, ctx.Req.UserAgent(), str)
|
||||||
accessLogger := log.GetLogger("access")
|
accessLogger := log.GetLogger("access")
|
||||||
accessLogger.SendLog(log.INFO, "", "", 0, fmt.Sprintf("%+v\n", logTemplate), "")
|
accessLogger.SendLog(log.INFO, "", "", 0, logTemplate, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
if newBranchLen != oldBranchLen{
|
if newBranchLen != oldBranchLen{
|
||||||
|
@ -98,20 +102,14 @@ func CompareCommitAndBranch(ctx *context.Context, repo *models.Repository, oldGr
|
||||||
|
|
||||||
if newBranchLen < oldBranchLen {
|
if newBranchLen < oldBranchLen {
|
||||||
branch := FindBranch(oldBranches, newBranches)
|
branch := FindBranch(oldBranches, newBranches)
|
||||||
str = fmt.Sprintf("{action: createBranch, branch_name: %v}", branch.Name)
|
str = fmt.Sprintf("{action: deleteBranch, branch_name: %v}", branch.Name)
|
||||||
}
|
|
||||||
logTemplate := LogTemplate{
|
|
||||||
login: " "+identity,
|
|
||||||
time: " "+time.Now().Format("2006-01-02 15:04:05 -0700"),
|
|
||||||
method: " "+ctx.Req.Method,
|
|
||||||
uri: " "+ctx.Req.URL.RequestURI(),
|
|
||||||
proto: " "+ctx.Req.Proto,
|
|
||||||
response_code: " -",
|
|
||||||
agent: " "+ctx.Req.UserAgent(),
|
|
||||||
request_body: " "+str,
|
|
||||||
}
|
}
|
||||||
|
logTemplate := fmt.Sprintf(
|
||||||
|
"{login: %s, time: %s, method: %s, uri: %s, proto: %s, response_code: -, agent: %s, request_body: %s}",
|
||||||
|
identity, time.Now().Format("2006-01-02 15:04:05 -0700"), ctx.Req.Method,
|
||||||
|
ctx.Req.URL.RequestURI(), ctx.Req.Proto, ctx.Req.UserAgent(), str)
|
||||||
accessLogger := log.GetLogger("access")
|
accessLogger := log.GetLogger("access")
|
||||||
accessLogger.SendLog(log.INFO, "", "", 0, fmt.Sprintf("%+v\n", logTemplate), "")
|
accessLogger.SendLog(log.INFO, "", "", 0, logTemplate, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -138,7 +136,10 @@ func CompareGraph(newGraph []GraphItem, oldGraph []GraphItem)([]GraphItem) {
|
||||||
func StringfyGraph(Graph []GraphItem)(string){
|
func StringfyGraph(Graph []GraphItem)(string){
|
||||||
str := "{action: commit, payload: ["
|
str := "{action: commit, payload: ["
|
||||||
for i := 0; i < len(Graph); i++{
|
for i := 0; i < len(Graph); i++{
|
||||||
str += fmt.Sprintf("%+v, ", Graph[i])
|
//str += fmt.Sprintf("%+v, ", Graph[i])
|
||||||
|
str += fmt.Sprintf("{GraphAcii: %s, Relation: %s, Branch: %s, Rev: %s, Date: %s, Author: %s, AuthorEmail: %s, ShortRev: %s, Subject: %s, OnlyRelation: %v}",
|
||||||
|
Graph[i].GraphAcii, Graph[i].Relation, Graph[i].Branch, Graph[i].Rev, Graph[i].Date, Graph[i].Author,
|
||||||
|
Graph[i].AuthorEmail, Graph[i].ShortRev, Graph[i].Subject, Graph[i].OnlyRelation)
|
||||||
}
|
}
|
||||||
str += "]}"
|
str += "]}"
|
||||||
return str
|
return str
|
||||||
|
|
Loading…
Reference in New Issue