Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rm gin #154

Merged
merged 2 commits into from
Oct 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 0 additions & 150 deletions api/controller/modules.go

This file was deleted.

1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ require (
github.com/filecoin-project/venus-auth v1.2.2-0.20210716071053-565a8999f9e5
github.com/filecoin-project/venus-wallet v1.1.0
github.com/gbrlsnchs/jwt/v3 v3.0.0
github.com/gin-gonic/gin v1.6.3
github.com/google/uuid v1.2.0
github.com/hraban/lrucache v0.0.0-20201130153820-17052bf09781 // indirect
github.com/hunjixin/automapper v0.0.0-20191127090318-9b979ce72ce2
Expand Down
82 changes: 1 addition & 81 deletions log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@ package log

import (
"context"
"fmt"
"math"
"net/http"
"os"
"time"

"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
"golang.org/x/xerrors"
"os"

"github.com/filecoin-project/venus-messager/config"
)
Expand Down Expand Up @@ -53,77 +47,3 @@ func (logger *Logger) SetLogLevel(ctx context.Context, levelStr string) error {

return nil
}

// 2016-09-27 09:38:21.541541811 +0200 CEST
// 127.0.0.1 - frank [2021-04-09 15:58:00]
// "GET /apache_pb.gif HTTP/1.0" 200 2326
// "http://www.example.com/start.html"
// "Mozilla/4.08 [en] (Win98; I ;Nav)"
// copy from https://github.com/toorop/gin-logrus/blob/master/logger.go

var timeFormat = "2006-01-02 15:04:05"

// GinLogrus is the logrus logger handler
func GinLogrus(logger logrus.FieldLogger, notLogged ...string) gin.HandlerFunc {
hostname, err := os.Hostname()
if err != nil {
hostname = "unknow"
}

var skip map[string]struct{}

if length := len(notLogged); length > 0 {
skip = make(map[string]struct{}, length)

for _, p := range notLogged {
skip[p] = struct{}{}
}
}

return func(c *gin.Context) {
// other handler can change c.Path so:
path := c.Request.URL.Path
start := time.Now()
c.Next()
stop := time.Since(start)
latency := int(math.Ceil(float64(stop.Nanoseconds()) / 1000000.0))
statusCode := c.Writer.Status()
clientIP := c.ClientIP()
clientUserAgent := c.Request.UserAgent()
referer := c.Request.Referer()
dataLength := c.Writer.Size()
if dataLength < 0 {
dataLength = 0
}

if _, ok := skip[path]; ok {
return
}

entry := logger.WithFields(logrus.Fields{
"hostname": hostname,
"statusCode": statusCode,
"latency": latency, // time to process
"clientIP": clientIP,
"method": c.Request.Method,
"path": path,
"referer": referer,
"dataLength": dataLength,
"userAgent": clientUserAgent,
})

if len(c.Errors) > 0 {
entry.Error(c.Errors.ByType(gin.ErrorTypePrivate).String())
} else {
msg := fmt.Sprintf("%s - %s [%s] \"%s %s\" %d %d \"%s\" \"%s\" (%dms)", clientIP, hostname,
time.Now().Format(timeFormat), c.Request.Method, path, statusCode, dataLength, referer, clientUserAgent, latency)
if statusCode >= http.StatusInternalServerError {
entry.Error(msg)
} else if statusCode >= http.StatusBadRequest {
entry.Warn(msg)
} else {
entry.Debug(msg)
}
}
}
}