Skip to content

Commit

Permalink
Fix issue where default go logger is not discarded when either * or s…
Browse files Browse the repository at this point in the history
…tdout is selected. Fix elastic#10251.
  • Loading branch information
blakerouse committed Jan 24, 2020
1 parent e2f20e5 commit b1613a2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion libbeat/logp/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ import (
)

var (
_log unsafe.Pointer // Pointer to a coreLogger. Access via atomic.LoadPointer.
_log unsafe.Pointer // Pointer to a coreLogger. Access via atomic.LoadPointer.
_defaultGoLog = golog.Writer()
)

func init() {
Expand Down Expand Up @@ -104,6 +105,8 @@ func Configure(cfg Config) error {
// Disable standard logging by default (this is sometimes used by
// libraries and we don't want their spam).
golog.SetOutput(ioutil.Discard)
} else {
golog.SetOutput(_defaultGoLog)
}

sink = selectiveWrapper(sink, selectors)
Expand Down
13 changes: 13 additions & 0 deletions libbeat/logp/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package logp

import (
"io/ioutil"
golog "log"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -116,3 +118,14 @@ func TestL(t *testing.T) {
assert.Equal(t, "warning 1", log.Message)
}
}

func TestAllStdoutDisablesDefaultGoLogger(t *testing.T) {
DevelopmentSetup(WithSelectors("*"))
assert.Equal(t, ioutil.Discard, golog.Writer())

DevelopmentSetup(WithSelectors("stdlog"))
assert.Equal(t, ioutil.Discard, golog.Writer())

DevelopmentSetup(WithSelectors("*", "stdlog"))
assert.NotEqual(t, ioutil.Discard, golog.Writer())
}

0 comments on commit b1613a2

Please sign in to comment.