forked from mirror/logrus
Remove sensitivity to file line changes
This commit is contained in:
parent
a6668e7a60
commit
e8fd0ba609
|
@ -3,9 +3,11 @@ package logrus_test
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
@ -338,6 +340,7 @@ func TestNestedLoggingReportsCorrectCaller(t *testing.T) {
|
||||||
llog := logger.WithField("context", "eating raw fish")
|
llog := logger.WithField("context", "eating raw fish")
|
||||||
|
|
||||||
llog.Info("looks delicious")
|
llog.Info("looks delicious")
|
||||||
|
_, _, line, _ := runtime.Caller(0)
|
||||||
|
|
||||||
err := json.Unmarshal(buffer.Bytes(), &fields)
|
err := json.Unmarshal(buffer.Bytes(), &fields)
|
||||||
require.NoError(t, err, "should have decoded first message")
|
require.NoError(t, err, "should have decoded first message")
|
||||||
|
@ -348,7 +351,7 @@ func TestNestedLoggingReportsCorrectCaller(t *testing.T) {
|
||||||
"github.com/sirupsen/logrus_test.TestNestedLoggingReportsCorrectCaller", fields["func"])
|
"github.com/sirupsen/logrus_test.TestNestedLoggingReportsCorrectCaller", fields["func"])
|
||||||
cwd, err := os.Getwd()
|
cwd, err := os.Getwd()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, filepath.ToSlash(cwd+"/logrus_test.go:340"), filepath.ToSlash(fields["file"].(string)))
|
assert.Equal(t, filepath.ToSlash(fmt.Sprintf("%s/logrus_test.go:%d", cwd, line-1)), filepath.ToSlash(fields["file"].(string)))
|
||||||
|
|
||||||
buffer.Reset()
|
buffer.Reset()
|
||||||
|
|
||||||
|
@ -363,6 +366,7 @@ func TestNestedLoggingReportsCorrectCaller(t *testing.T) {
|
||||||
}).WithFields(Fields{
|
}).WithFields(Fields{
|
||||||
"James": "Brown",
|
"James": "Brown",
|
||||||
}).Print("The hardest workin' man in show business")
|
}).Print("The hardest workin' man in show business")
|
||||||
|
_, _, line, _ = runtime.Caller(0)
|
||||||
|
|
||||||
err = json.Unmarshal(buffer.Bytes(), &fields)
|
err = json.Unmarshal(buffer.Bytes(), &fields)
|
||||||
assert.NoError(t, err, "should have decoded second message")
|
assert.NoError(t, err, "should have decoded second message")
|
||||||
|
@ -377,7 +381,7 @@ func TestNestedLoggingReportsCorrectCaller(t *testing.T) {
|
||||||
assert.Equal(t,
|
assert.Equal(t,
|
||||||
"github.com/sirupsen/logrus_test.TestNestedLoggingReportsCorrectCaller", fields["func"])
|
"github.com/sirupsen/logrus_test.TestNestedLoggingReportsCorrectCaller", fields["func"])
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, filepath.ToSlash(cwd+"/logrus_test.go:365"), filepath.ToSlash(fields["file"].(string)))
|
assert.Equal(t, filepath.ToSlash(fmt.Sprintf("%s/logrus_test.go:%d", cwd, line-1)), filepath.ToSlash(fields["file"].(string)))
|
||||||
|
|
||||||
logger.ReportCaller = false // return to default value
|
logger.ReportCaller = false // return to default value
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue