Bläddra i källkod

Logger only prints internal errors

Manu Mtz-Almeida 10 år sedan
förälder
incheckning
dde06a07f0
3 ändrade filer med 4 tillägg och 3 borttagningar
  1. 2 2
      errors.go
  2. 1 0
      errors_test.go
  3. 1 1
      logger.go

+ 2 - 2
errors.go

@@ -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)

+ 1 - 0
errors_test.go

@@ -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

+ 1 - 1
logger.go

@@ -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"),