From 524b200631467fc656cb67ba59b06224ad64bc8a Mon Sep 17 00:00:00 2001 From: Hank Shen Date: Mon, 22 Mar 2021 10:35:41 +0800 Subject: [PATCH] update --- go.mod | 4 +-- go.sum | 8 ++--- vendor/github.com/admpub/log/default.go | 4 +++ vendor/github.com/admpub/log/logger.go | 20 +++++++------ vendor/github.com/admpub/log/logger_core.go | 29 +------------------ vendor/github.com/webx-top/echo/constant.go | 7 +++++ .../webx-top/echo/variable_default.go | 28 +++++++++--------- vendor/modules.txt | 4 +-- 8 files changed, 45 insertions(+), 59 deletions(-) diff --git a/go.mod b/go.mod index 59c59d2..1f74073 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/admpub/fsnotify v1.4.4 github.com/admpub/go-reuseport v0.0.3 // indirect github.com/admpub/humanize v0.0.0-20190501023926-5f826e92c8ca // indirect - github.com/admpub/log v0.0.2 + github.com/admpub/log v0.2.0 github.com/admpub/manners v0.0.0-20160501130611-72097fd728f7 // indirect github.com/braintree/manners v0.0.0-20160418043613-82a8879fc5fd // indirect github.com/francoispqt/gojay v1.2.13 // indirect @@ -23,7 +23,7 @@ require ( github.com/stretchr/testify v1.7.0 github.com/webx-top/captcha v0.0.0-20161202061115-29e9e7f30aa0 // indirect github.com/webx-top/com v0.1.2 - github.com/webx-top/echo v2.8.2+incompatible // indirect + github.com/webx-top/echo v2.8.3+incompatible // indirect github.com/webx-top/reverseproxy v0.0.2 github.com/webx-top/tagfast v0.0.0-20161020041435-9a2065ce3dd2 // indirect github.com/webx-top/validation v0.0.1 // indirect diff --git a/go.sum b/go.sum index 69c2bf3..71dc7c6 100644 --- a/go.sum +++ b/go.sum @@ -26,8 +26,8 @@ github.com/admpub/go-reuseport v0.0.3 h1:K9gDKC2Alx77JC2NibDIfXouFosHlQ44JqV4ttO github.com/admpub/go-reuseport v0.0.3/go.mod h1:d5DFsbZ3EvwDW86DFRhpK/IIS96EwYBLjvWl6w1QqP0= github.com/admpub/humanize v0.0.0-20190501023926-5f826e92c8ca h1:9mfauR3d9p41BFnAoXmHc2z8yHcgg+3+jT1hbnQrtXo= github.com/admpub/humanize v0.0.0-20190501023926-5f826e92c8ca/go.mod h1:eHL6IsGOvDKqPc9Zp0d0NNayoEYoJ+UC+vj6zG0lGCY= -github.com/admpub/log v0.0.2 h1:XDg8G5XIOIDBOkkeJPYnjb+snNpGgzexIzGK2cai6Zo= -github.com/admpub/log v0.0.2/go.mod h1:rr6Sw/xAGWzL/Hg7FCekKd98XguStEEjcYC/DG5y/YA= +github.com/admpub/log v0.2.0 h1:4vuA5wmk/z9x2gT3lN7OTN4NbNQ1cVb+tAu0CyykYXg= +github.com/admpub/log v0.2.0/go.mod h1:rr6Sw/xAGWzL/Hg7FCekKd98XguStEEjcYC/DG5y/YA= github.com/admpub/manners v0.0.0-20160501130611-72097fd728f7 h1:UIU46MHldBEyGh5lrv2oP7LKHzrLV5ASXZHHRffXy1k= github.com/admpub/manners v0.0.0-20160501130611-72097fd728f7/go.mod h1:qvQUcftumm7cJ11nhqPGVzm2INF9RWpGNRJeJfpSyT8= github.com/admpub/map2struct v0.0.5 h1:NP/2mvqaD3QYYEbcNz2tIcTEyuW0sqIDLiuoBsNMUmY= @@ -168,8 +168,8 @@ github.com/webx-top/captcha v0.0.0-20161202061115-29e9e7f30aa0 h1:KkrDcd2yO7QHeJ github.com/webx-top/captcha v0.0.0-20161202061115-29e9e7f30aa0/go.mod h1:DLtQXR6uR8UMcKb7dB5eYgsDHG0WPI74rM/B/JFGxfE= github.com/webx-top/com v0.1.2 h1:pAsQmYbcgoVzM/TKePP2EQET4lTmDEK5a23uwo5f4G4= github.com/webx-top/com v0.1.2/go.mod h1:DDfATzu1w5+vD5XmG3YRTfLjaIqZWi/yeJ7HQEGsM2Q= -github.com/webx-top/echo v2.8.2+incompatible h1:1By7LOPqHTANxRzbbOO5AQRmzbJvxgj6mOqzaiHm0xo= -github.com/webx-top/echo v2.8.2+incompatible/go.mod h1:ufVP//GwP1suggBSQW7l8G9XcKxZM+FIfCMElLAQqF8= +github.com/webx-top/echo v2.8.3+incompatible h1:A1HCzSzapfzwu59sAsOLqBPGLTl8TZLZskygIYPqz0I= +github.com/webx-top/echo v2.8.3+incompatible/go.mod h1:ufVP//GwP1suggBSQW7l8G9XcKxZM+FIfCMElLAQqF8= github.com/webx-top/reverseproxy v0.0.2 h1:V/ylAOiPQvgDj3SUNJJnQlc17oM/B4ZU3Aq+TxDjY2I= github.com/webx-top/reverseproxy v0.0.2/go.mod h1:yCbmmzm+kjreKSMNB4nBQsWrUfa+EUN9HqiXDKX82Hk= github.com/webx-top/tagfast v0.0.0-20161020041435-9a2065ce3dd2 h1:lqnGa1BnWT7pN+c9V31bik0lTp5XxyOMRp7ICsZ6K5M= diff --git a/vendor/github.com/admpub/log/default.go b/vendor/github.com/admpub/log/default.go index 001ef86..45fe887 100644 --- a/vendor/github.com/admpub/log/default.go +++ b/vendor/github.com/admpub/log/default.go @@ -90,6 +90,10 @@ func Writer(level Level) io.Writer { return DefaultLog.Writer(level) } +func Close() { + DefaultLog.Close() +} + func UseCommonTargets(levelName string, targetNames ...string) *Logger { DefaultLog.SetLevel(levelName) targets := []Target{} diff --git a/vendor/github.com/admpub/log/logger.go b/vendor/github.com/admpub/log/logger.go index 8eecd2f..98c4eb6 100644 --- a/vendor/github.com/admpub/log/logger.go +++ b/vendor/github.com/admpub/log/logger.go @@ -9,8 +9,6 @@ import ( "fmt" "io" "os" - "sync" - "sync/atomic" "time" ) @@ -42,7 +40,7 @@ func NewLogger(args ...string) *Logger { MaxLevel: LevelDebug, CallStack: make(map[Leveler]*CallStack), Targets: make([]Target, 0), - waiting: &sync.Once{}, + fatalAction: ActionPanic, } category := `app` if len(args) > 0 { @@ -103,17 +101,21 @@ func (l *Logger) Sync(args ...bool) *Logger { } func (l *Logger) sendEntry(entry *Entry) { - atomic.AddUint32(&l.sendN, 1) l.entries <- entry } // Async 异步日志 func (l *Logger) Async(args ...bool) *Logger { + var syncMode bool if len(args) < 1 { - l.syncMode = false + syncMode = false + } else { + syncMode = !args[0] + } + if l.syncMode == syncMode { return l } - l.syncMode = !args[0] + l.syncMode = syncMode if l.open { l.Close() l.Open() @@ -251,9 +253,8 @@ func (l *Logger) Debug(a ...interface{}) { // Log logs a message of a specified severity level. func (l *Logger) Log(level Leveler, a ...interface{}) { l.lock.RLock() - defer l.lock.RUnlock() - if level.Int() > l.MaxLevel.Int() || !l.open { + l.lock.RUnlock() return } var message string @@ -263,6 +264,7 @@ func (l *Logger) Log(level Leveler, a ...interface{}) { } else { message = fmt.Sprint(a...) } + l.lock.RUnlock() l.newEntry(level, message) } @@ -278,11 +280,11 @@ func (l *Logger) newEntry(level Leveler, message string) { l.generateCallStack(entry, level, true) entry.FormattedMessage = l.Formatter(l, entry) l.sendEntry(entry) - l.wait() switch l.fatalAction { case ActionPanic: panic(entry.FormattedMessage) case ActionExit: + l.Close() os.Exit(-1) } return diff --git a/vendor/github.com/admpub/log/logger_core.go b/vendor/github.com/admpub/log/logger_core.go index 334e462..9b88f8f 100644 --- a/vendor/github.com/admpub/log/logger_core.go +++ b/vendor/github.com/admpub/log/logger_core.go @@ -5,8 +5,6 @@ import ( "fmt" "io" "sync" - "sync/atomic" - "time" ) // coreLogger maintains the log messages in a channel and sends them to various targets. @@ -14,11 +12,8 @@ type coreLogger struct { lock sync.RWMutex open bool // whether the logger is open entries chan *Entry // log entries - sendN uint32 - procsN uint32 - waiting *sync.Once fatalAction Action - syncMode bool // Whether the use of non-asynchronous mode (是否使用非异步模式) + syncMode bool ErrorWriter io.Writer // the writer used to write errors caused by log targets BufferSize int // the size of the channel storing log entries @@ -29,26 +24,6 @@ type coreLogger struct { AddSpace bool // Add a space between two arguments. } -func (l *coreLogger) wait() { - l.waiting.Do(func() { - for { - sendN := atomic.LoadUint32(&l.sendN) - //fmt.Println(`waiting ...`, len(l.entries), sendN) - if sendN <= atomic.LoadUint32(&l.procsN) { - l.sendN = 0 - l.procsN = 0 - l.waiting = &sync.Once{} - return - } - delay := sendN - if delay < 500 { - delay = 500 - } - time.Sleep(time.Duration(delay) * time.Microsecond) - } - }) -} - // Open prepares the logger and the targets for logging purpose. // Open must be called before any message can be logged. func (l *coreLogger) Open() error { @@ -96,7 +71,6 @@ func (l *coreLogger) process() { if entry == nil { break } - atomic.AddUint32(&l.procsN, 1) } } @@ -111,7 +85,6 @@ func (l *coreLogger) Close() { return } l.open = false - l.wait() // use a nil entry to signal the close of logger l.entries <- nil for _, target := range l.Targets { diff --git a/vendor/github.com/webx-top/echo/constant.go b/vendor/github.com/webx-top/echo/constant.go index 59147b1..31f9f55 100644 --- a/vendor/github.com/webx-top/echo/constant.go +++ b/vendor/github.com/webx-top/echo/constant.go @@ -116,4 +116,11 @@ const ( HeaderXCSRFToken = "X-CSRF-Token" FilePathSeparator = string(filepath.Separator) + + // Content Type + ContentTypeHTML = "html" + ContentTypeJSON = "json" + ContentTypeJSONP = "jsonp" + ContentTypeXML = "xml" + ContentTypeText = "text" ) diff --git a/vendor/github.com/webx-top/echo/variable_default.go b/vendor/github.com/webx-top/echo/variable_default.go index ec8dc81..172a28a 100644 --- a/vendor/github.com/webx-top/echo/variable_default.go +++ b/vendor/github.com/webx-top/echo/variable_default.go @@ -30,36 +30,36 @@ import ( var ( DefaultAcceptFormats = map[string]string{ //json - `application/json`: `json`, - `text/javascript`: `json`, - `application/javascript`: `json`, + MIMEApplicationJSON: ContentTypeJSON, + `text/javascript`: ContentTypeJSON, + MIMEApplicationJavaScript: ContentTypeJSON, //xml - `application/xml`: `xml`, - `text/xml`: `xml`, + MIMEApplicationXML: ContentTypeXML, + `text/xml`: ContentTypeXML, //text - `text/plain`: `text`, + MIMETextPlain: ContentTypeText, //html - `*/*`: `html`, - `application/xhtml`: `html`, - `text/html`: `html`, + `*/*`: ContentTypeHTML, + `application/xhtml`: ContentTypeHTML, + MIMETextHTML: ContentTypeHTML, //default - `*`: `html`, + `*`: ContentTypeHTML, } DefaultFormatRenderers = map[string]func(c Context, data interface{}) error{ - `json`: func(c Context, data interface{}) error { + ContentTypeJSON: func(c Context, data interface{}) error { return c.JSON(c.Data()) }, - `jsonp`: func(c Context, data interface{}) error { + ContentTypeJSONP: func(c Context, data interface{}) error { return c.JSONP(c.Query(c.Echo().JSONPVarName), c.Data()) }, - `xml`: func(c Context, data interface{}) error { + ContentTypeXML: func(c Context, data interface{}) error { return c.XML(c.Data()) }, - `text`: func(c Context, data interface{}) error { + ContentTypeText: func(c Context, data interface{}) error { return c.String(fmt.Sprint(data)) }, } diff --git a/vendor/modules.txt b/vendor/modules.txt index 9ffe0a6..e7fe2e8 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -27,7 +27,7 @@ github.com/admpub/go-reuseport # github.com/admpub/humanize v0.0.0-20190501023926-5f826e92c8ca ## explicit github.com/admpub/humanize -# github.com/admpub/log v0.0.2 +# github.com/admpub/log v0.2.0 ## explicit github.com/admpub/log # github.com/admpub/manners v0.0.0-20160501130611-72097fd728f7 @@ -89,7 +89,7 @@ github.com/webx-top/captcha ## explicit github.com/webx-top/com github.com/webx-top/com/encoding/json -# github.com/webx-top/echo v2.8.2+incompatible +# github.com/webx-top/echo v2.8.3+incompatible ## explicit github.com/webx-top/echo github.com/webx-top/echo/code