forked from mirror/gin
Logger only prints internal errors
This commit is contained in:
parent
70325deb98
commit
dde06a07f0
|
@ -80,9 +80,9 @@ func (msg *Error) Error() string {
|
|||
// ie ByType(gin.ErrorTypePublic) returns a slice of errors with type=ErrorTypePublic
|
||||
func (a errorMsgs) ByType(typ ErrorType) errorMsgs {
|
||||
if len(a) == 0 {
|
||||
return a
|
||||
return nil
|
||||
}
|
||||
result := make(errorMsgs, 0, len(a))
|
||||
var result errorMsgs = nil
|
||||
for _, msg := range a {
|
||||
if msg.Type&typ > 0 {
|
||||
result = append(result, msg)
|
||||
|
|
|
@ -69,6 +69,7 @@ func TestErrorSlice(t *testing.T) {
|
|||
assert.Equal(t, errs.ByType(ErrorTypePrivate).Errors(), []string{"first", "second"})
|
||||
assert.Equal(t, errs.ByType(ErrorTypePublic|ErrorTypePrivate).Errors(), []string{"first", "second", "third"})
|
||||
assert.Empty(t, errs.ByType(ErrorTypeBind))
|
||||
assert.Empty(t, errs.ByType(ErrorTypeBind).String())
|
||||
|
||||
assert.Equal(t, errs.String(), `Error #01: first
|
||||
Error #02: second
|
||||
|
|
|
@ -64,7 +64,7 @@ func LoggerWithWriter(out io.Writer) HandlerFunc {
|
|||
statusCode := c.Writer.Status()
|
||||
statusColor := colorForStatus(statusCode)
|
||||
methodColor := colorForMethod(method)
|
||||
comment := c.Errors.String()
|
||||
comment := c.Errors.ByType(ErrorTypePrivate).String()
|
||||
|
||||
fmt.Fprintf(out, "[GIN] %v |%s %3d %s| %13v | %s |%s %s %-7s %s\n%s",
|
||||
end.Format("2006/01/02 - 15:04:05"),
|
||||
|
|
Loading…
Reference in New Issue