Logrus: All tests broken with Go 1.14 beta1

Created on 4 Feb 2020  Â·  13Comments  Â·  Source: sirupsen/logrus

Fedora Rawhide with Go 1.14 beta1

Testing    in: /builddir/build/BUILD/logrus-1.4.2/_build/src
         PATH: /builddir/build/BUILD/logrus-1.4.2/_build/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin
       GOPATH: /builddir/build/BUILD/logrus-1.4.2/_build:/usr/share/gocode
  GO111MODULE: off
      command: go test -buildmode pie -compiler gc -ldflags "-X github.com/sirupsen/logrus/version=1.4.2 -extldflags '-Wl,-z,relro -Wl,--as-needed  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld '"
      testing: github.com/sirupsen/logrus
github.com/sirupsen/logrus
{"level":"info","logrus_error":"can not add field \"func\"","msg":"test","time":"2020-02-04T19:25:53Z"}
{"level":"info","msg":"test","str":"str","time":"2020-02-04T19:25:53Z"}
--- FAIL: TestReportCallerWhenConfigured (0.00s)
    logrus_test.go:42: 
            Error Trace:    logrus_test.go:42
                                        testutils.go:28
                                        logrus_test.go:36
            Error:          Not equal: 
                            expected: "github.com/sirupsen/logrus_test.TestReportCallerWhenConfigured.func3"
                            actual  : "github.com/sirupsen/logrus.(*Entry).Info"

                            Diff:
                            --- Expected
                            +++ Actual
                            @@ -1 +1 @@
                            -github.com/sirupsen/logrus_test.TestReportCallerWhenConfigured.func3
                            +github.com/sirupsen/logrus.(*Entry).Info
            Test:           TestReportCallerWhenConfigured
--- FAIL: TestReportCallerHelperDirect (0.00s)
    logrus_test.go:96: 
            Error Trace:    logrus_test.go:96
            Error:          Expect "github.com/sirupsen/logrus.(*Entry).Info" to match "github.com/.*/logrus_test.logSomething"
            Test:           TestReportCallerHelperDirect
--- FAIL: TestReportCallerHelperViaPointer (0.00s)
    logrus_test.go:106: 
            Error Trace:    logrus_test.go:106
            Error:          Expect "github.com/sirupsen/logrus.(*Entry).Info" to match "github.com/.*/logrus_test.logSomething"
            Test:           TestReportCallerHelperViaPointer
--- FAIL: TestNestedLoggingReportsCorrectCaller (0.00s)
    logrus_test.go:381: 
            Error Trace:    logrus_test.go:381
            Error:          Not equal: 
                            expected: "github.com/sirupsen/logrus_test.TestNestedLoggingReportsCorrectCaller"
                            actual  : "github.com/sirupsen/logrus.(*Entry).Info"

                            Diff:
                            --- Expected
                            +++ Actual
                            @@ -1 +1 @@
                            -github.com/sirupsen/logrus_test.TestNestedLoggingReportsCorrectCaller
                            +github.com/sirupsen/logrus.(*Entry).Info
            Test:           TestNestedLoggingReportsCorrectCaller
    logrus_test.go:385: 
            Error Trace:    logrus_test.go:385
            Error:          Not equal: 
                            expected: "/builddir/build/BUILD/logrus-1.4.2/_build/src/github.com/sirupsen/logrus/logrus_test.go:373"
                            actual  : "/builddir/build/BUILD/logrus-1.4.2/_build/src/github.com/sirupsen/logrus/entry.go:285"

                            Diff:
                            --- Expected
                            +++ Actual
                            @@ -1 +1 @@
                            -/builddir/build/BUILD/logrus-1.4.2/_build/src/github.com/sirupsen/logrus/logrus_test.go:373
                            +/builddir/build/BUILD/logrus-1.4.2/_build/src/github.com/sirupsen/logrus/entry.go:285
            Test:           TestNestedLoggingReportsCorrectCaller
    logrus_test.go:412: 
            Error Trace:    logrus_test.go:412
            Error:          Not equal: 
                            expected: "github.com/sirupsen/logrus_test.TestNestedLoggingReportsCorrectCaller"
                            actual  : "github.com/sirupsen/logrus.(*Entry).Info"

                            Diff:
                            --- Expected
                            +++ Actual
                            @@ -1 +1 @@
                            -github.com/sirupsen/logrus_test.TestNestedLoggingReportsCorrectCaller
                            +github.com/sirupsen/logrus.(*Entry).Info
            Test:           TestNestedLoggingReportsCorrectCaller
    logrus_test.go:415: 
            Error Trace:    logrus_test.go:415
            Error:          Not equal: 
                            expected: "/builddir/build/BUILD/logrus-1.4.2/_build/src/github.com/sirupsen/logrus/logrus_test.go:399"
                            actual  : "/builddir/build/BUILD/logrus-1.4.2/_build/src/github.com/sirupsen/logrus/entry.go:285"

                            Diff:
                            --- Expected
                            +++ Actual
                            @@ -1 +1 @@
                            -/builddir/build/BUILD/logrus-1.4.2/_build/src/github.com/sirupsen/logrus/logrus_test.go:399
                            +/builddir/build/BUILD/logrus-1.4.2/_build/src/github.com/sirupsen/logrus/entry.go:285
            Test:           TestNestedLoggingReportsCorrectCaller
time="2020-02-04T19:25:53Z" level=info msg=info
time="2020-02-04T19:25:53Z" level=info msg=info context=clue wow=whale

INFO[0000] test                                          file=file func=func
time="2020-02-04T19:25:53Z" level=info msg=test file=file func=func
--- FAIL: ExampleCustomFormatter (0.00s)
got:
{"file":"logger.go","func":"Log","level":"info","msg":"example of custom format caller"}
want:
{"file":"example_custom_caller_test.go","func":"ExampleCustomFormatter","level":"info","msg":"example of custom format caller"}
FAIL
exit status 1
FAIL    github.com/sirupsen/logrus  0.780s
bug

Most helpful comment

Sorry to bother. But can we have a new tag to address this issue?

All 13 comments

do we have a release date for go1.14 already ?
I suggest we wait for its release before fixing things

go 1.14 is already released

I assume this is related to the issue I'm seeing with go 1.14.

When I set logrus.SetReportCaller(true), I see fields like this logged:

{
  "file": "/Users/tschaub/go/pkg/mod/github.com/sirupsen/[email protected]/entry.go:285",
  "func": "github.com/sirupsen/logrus.(*Entry).Info"
}

Perhaps @v1.4.2 is causing trouble with the getPackageName function?

Update: I see this reported in #1089 now.

I see the problem here:
github.com/sirupsen/[email protected]/entry.go
line 167:function getCaller

func getCaller() *runtime.Frame {

    // cache this package's fully-qualified name
    callerInitOnce.Do(func() {
        pcs := make([]uintptr, 2)
        _ = runtime.Callers(0, pcs)
        **logrusPackage = getPackageName(runtime.FuncForPC(pcs[1]).Name())**

        // now that we have the cache, we can skip a minimum count of known-logrus functions
        // XXX this is dubious, the number of frames may vary
        minimumCallerDepth = knownLogrusFrames
    })

The variable ’logrusPackage‘’'v value is wrong.
I'm just going to rewrite it as:logrusPackage = "github.com/sirupsen/logrus" , It works.

In addition, it works In debug mode.

I see the problem here:

logrusPackage = getPackageName(runtime.FuncForPC(pcs[1]).Name())

Modified to:

logrusPackage = getPackageName(runtime.FuncForPC(pcs[0]).Name())

It works.

Go 1.14

// getCaller retrieves the name of the first non-logrus calling function
func getCaller() *runtime.Frame {

    // cache this package's fully-qualified name
    callerInitOnce.Do(func() {
        pcs := make([]uintptr, maximumCallerDepth)
        _ = runtime.Callers(0, pcs)
        // dynamic get the package name and the minimum caller depth will has a mostly compatibility of go version
        for i := 0; i < maximumCallerDepth; i++ {
            funcName := runtime.FuncForPC(pcs[i]).Name()
            if strings.Contains(funcName, "getCaller")  {
                logrusPackage = getPackageName(funcName)
                                 break;
            }
        }
    })

I tested @heramerom code and it works for me, with go version go1.14 linux/amd64.

However @heramom, I noticed you do no more:

minimumCallerDepth = knownLogrusFrames

Is it a desired behavior?

@dgsb

do we have a release date for go1.14 already ?
I suggest we wait for its release before fixing things

Go 1.14 has been released! https://blog.golang.org/go1.14

I see we have the solution. Is someone working on a PR for this issue?

@panshul007 I see you are primed and eager to help :smile:. You are welcome to take a shot at it :1st_place_medal: :+1:

@panshul007 @chibby0ne I did it! See #1108

I built and tried my project with my fork with both 1.13 and 1.14 with no issue.

Sorry to bother. But can we have a new tag to address this issue?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

oconnor663 picture oconnor663  Â·  3Comments

anoop-nair picture anoop-nair  Â·  3Comments

kubistika picture kubistika  Â·  3Comments

UnAfraid picture UnAfraid  Â·  5Comments

psmason picture psmason  Â·  4Comments