Browse Source

logger: fix wrong callback method

Fix wrong callback in `logger.go`, and add test cases:

1. `logger.Warningln` should call `logger.Warnln`, not `logger.Warn`.

2. It's ok for `logger.Print` to call `entry.Info`, but calling `entry.Print`
   is better.

Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
tags/v1.4.0
Jiang Xin 10 months ago
parent
commit
f61e48bb8e
2 changed files with 25 additions and 2 deletions
  1. 2
    2
      logger.go
  2. 23
    0
      logger_test.go

+ 2
- 2
logger.go View File

@@ -200,7 +200,7 @@ func (logger *Logger) Info(args ...interface{}) {
200 200
 
201 201
 func (logger *Logger) Print(args ...interface{}) {
202 202
 	entry := logger.newEntry()
203
-	entry.Info(args...)
203
+	entry.Print(args...)
204 204
 	logger.releaseEntry(entry)
205 205
 }
206 206
 
@@ -256,7 +256,7 @@ func (logger *Logger) Warnln(args ...interface{}) {
256 256
 }
257 257
 
258 258
 func (logger *Logger) Warningln(args ...interface{}) {
259
-	logger.Warn(args...)
259
+	logger.Warnln(args...)
260 260
 }
261 261
 
262 262
 func (logger *Logger) Errorln(args ...interface{}) {

+ 23
- 0
logger_test.go View File

@@ -6,6 +6,7 @@ import (
6 6
 	"fmt"
7 7
 	"testing"
8 8
 
9
+	"github.com/stretchr/testify/assert"
9 10
 	"github.com/stretchr/testify/require"
10 11
 )
11 12
 
@@ -40,3 +41,25 @@ func TestNoFieldValueError(t *testing.T) {
40 41
 	_, ok := data[FieldKeyLogrusError]
41 42
 	require.False(t, ok)
42 43
 }
44
+
45
+func TestWarninglnNotEqualToWarning(t *testing.T) {
46
+	buf := &bytes.Buffer{}
47
+	bufln := &bytes.Buffer{}
48
+
49
+	formatter := new(TextFormatter)
50
+	formatter.DisableTimestamp = true
51
+	formatter.DisableLevelTruncation = true
52
+
53
+	l := &Logger{
54
+		Out:       buf,
55
+		Formatter: formatter,
56
+		Hooks:     make(LevelHooks),
57
+		Level:     DebugLevel,
58
+	}
59
+	l.Warning("hello,", "world")
60
+
61
+	l.SetOutput(bufln)
62
+	l.Warningln("hello,", "world")
63
+
64
+	assert.NotEqual(t, buf.String(), bufln.String(), "Warning() and Wantingln() should not be equal")
65
+}

Loading…
Cancel
Save