Skip to content

Commit

Permalink
Add missing logger init in New() functions (#16915)
Browse files Browse the repository at this point in the history
* Add missing logger init in New() functions
  • Loading branch information
kaiyan-sheng authored Mar 10, 2020
1 parent ad2672d commit e64a18f
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 2 deletions.
7 changes: 6 additions & 1 deletion libbeat/publisher/pipeline/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ type netClientWorker struct {

func makeClientWorker(observer outputObserver, qu workQueue, client outputs.Client) outputWorker {
if nc, ok := client.(outputs.NetworkClient); ok {
c := &netClientWorker{observer: observer, qu: qu, client: nc}
c := &netClientWorker{
observer: observer,
qu: qu,
client: nc,
logger: logp.NewLogger("publisher_pipeline_output"),
}
go c.run()
return c
}
Expand Down
1 change: 1 addition & 0 deletions libbeat/reader/multiline/multiline.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func New(
maxLines: maxLines,
separator: []byte(separator),
message: reader.Message{},
logger: logp.NewLogger("reader_multiline"),
}
return mlr, nil
}
Expand Down
1 change: 1 addition & 0 deletions libbeat/reader/readfile/line.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func NewLineReader(input io.Reader, config Config) (*LineReader, error) {
decodedNl: terminator,
inBuffer: streambuf.New(nil),
outBuffer: streambuf.New(nil),
logger: logp.NewLogger("reader_line"),
}, nil
}

Expand Down
1 change: 1 addition & 0 deletions libbeat/reader/readjson/docker_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func New(r reader.Reader, stream string, partial bool, format string, CRIFlags b
partial: partial,
reader: r,
criflags: CRIFlags,
logger: logp.NewLogger("reader_docker_json"),
}

switch strings.ToLower(format) {
Expand Down
6 changes: 5 additions & 1 deletion libbeat/reader/readjson/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ type JSONReader struct {

// NewJSONReader creates a new reader that can decode JSON.
func NewJSONReader(r reader.Reader, cfg *Config) *JSONReader {
return &JSONReader{reader: r, cfg: cfg}
return &JSONReader{
reader: r,
cfg: cfg,
logger: logp.NewLogger("reader_json"),
}
}

// decodeJSON unmarshals the text parameter into a MapStr and
Expand Down
3 changes: 3 additions & 0 deletions libbeat/reader/readjson/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"testing"
"time"

"github.com/elastic/beats/v7/libbeat/logp"

"github.com/stretchr/testify/assert"

"github.com/elastic/beats/v7/libbeat/common"
Expand Down Expand Up @@ -185,6 +187,7 @@ func TestDecodeJSON(t *testing.T) {

var p JSONReader
p.cfg = &test.Config
p.logger = logp.NewLogger("json_test")
text, M := p.decode([]byte(test.Text))
assert.Equal(t, test.ExpectedText, string(text))
assert.Equal(t, test.ExpectedMap, M)
Expand Down

0 comments on commit e64a18f

Please sign in to comment.