Skip to content

Commit

Permalink
日志输出优化
Browse files Browse the repository at this point in the history
  • Loading branch information
Becivells committed Sep 23, 2021
1 parent 154cd33 commit 37b3aca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
6 changes: 2 additions & 4 deletions internal/reverse/reverse.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,12 @@ func (reverse *Reverse) ServeHTTP(w http.ResponseWriter, r *http.Request) {
"url": r.URL.RequestURI(),
"request_ip": GetClientIP(r),
}).Info(dumpJson(r))
}
// dump
if logLevel == logrus.WarnLevel && r.Method == "POST" {
} else if logLevel == logrus.WarnLevel && r.Method == "POST" {
logging.AccLogger.WithFields(logrus.Fields{
"method": r.Method,
"url": r.URL.RequestURI(),
"request_ip": GetClientIP(r),
}).Info(dumpJson(r))
}).Warn(dumpJson(r))
}
log.Info("[c->p] host: %s,RemoteAddr: %s,URI: %s", host, GetClientIP(r), r.RequestURI)
//response
Expand Down
9 changes: 8 additions & 1 deletion pkg/logging/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
var outType []string = []string{"es7", "es6", "file", "syslog"}
var modeType = []string{"json", "text"}

//var logType = []string{"info", "warn", "warning", "error", "fatal"}

type Config struct {
Type string
LogLevel logrus.Level
Expand Down Expand Up @@ -53,8 +55,13 @@ func (conf *Config) New() (log *logrus.Logger) {

func (cf *Config) ValidateType() error {
if !utils.StrEqualOrInList(cf.Type, outType) {
return fmt.Errorf("log value %s type must %s ", cf.Type, strings.Join(outType, ","))
return fmt.Errorf("log value %s type must %s ", cf.Type, strings.Join(outType, ","))
}
// 永远不会执行
//if !utils.StrEqualOrInList(cf.LogLevel.String(), logType) {
// return fmt.Errorf("log type %s type must %s ", cf.LogLevel.String(), strings.Join(logType, ","))
//}

switch cf.Type {
case "file":
if !utils.StrEqualOrInList(cf.FileLog.Mode, modeType) {
Expand Down

0 comments on commit 37b3aca

Please sign in to comment.