diff --git a/internal/reverse/reverse.go b/internal/reverse/reverse.go index f8fab84..a3934af 100644 --- a/internal/reverse/reverse.go +++ b/internal/reverse/reverse.go @@ -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 diff --git a/pkg/logging/type.go b/pkg/logging/type.go index 85e853b..8b25b65 100644 --- a/pkg/logging/type.go +++ b/pkg/logging/type.go @@ -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 @@ -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) {