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
|
// ie ByType(gin.ErrorTypePublic) returns a slice of errors with type=ErrorTypePublic
|
||||||
func (a errorMsgs) ByType(typ ErrorType) errorMsgs {
|
func (a errorMsgs) ByType(typ ErrorType) errorMsgs {
|
||||||
if len(a) == 0 {
|
if len(a) == 0 {
|
||||||
return a
|
return nil
|
||||||
}
|
}
|
||||||
result := make(errorMsgs, 0, len(a))
|
var result errorMsgs = nil
|
||||||
for _, msg := range a {
|
for _, msg := range a {
|
||||||
if msg.Type&typ > 0 {
|
if msg.Type&typ > 0 {
|
||||||
result = append(result, msg)
|
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(ErrorTypePrivate).Errors(), []string{"first", "second"})
|
||||||
assert.Equal(t, errs.ByType(ErrorTypePublic|ErrorTypePrivate).Errors(), []string{"first", "second", "third"})
|
assert.Equal(t, errs.ByType(ErrorTypePublic|ErrorTypePrivate).Errors(), []string{"first", "second", "third"})
|
||||||
assert.Empty(t, errs.ByType(ErrorTypeBind))
|
assert.Empty(t, errs.ByType(ErrorTypeBind))
|
||||||
|
assert.Empty(t, errs.ByType(ErrorTypeBind).String())
|
||||||
|
|
||||||
assert.Equal(t, errs.String(), `Error #01: first
|
assert.Equal(t, errs.String(), `Error #01: first
|
||||||
Error #02: second
|
Error #02: second
|
||||||
|
|
|
@ -64,7 +64,7 @@ func LoggerWithWriter(out io.Writer) HandlerFunc {
|
||||||
statusCode := c.Writer.Status()
|
statusCode := c.Writer.Status()
|
||||||
statusColor := colorForStatus(statusCode)
|
statusColor := colorForStatus(statusCode)
|
||||||
methodColor := colorForMethod(method)
|
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",
|
fmt.Fprintf(out, "[GIN] %v |%s %3d %s| %13v | %s |%s %s %-7s %s\n%s",
|
||||||
end.Format("2006/01/02 - 15:04:05"),
|
end.Format("2006/01/02 - 15:04:05"),
|
||||||
|
|
Loading…
Reference in New Issue