From 86be93a633fc4ac342e4bef940ededf783521e04 Mon Sep 17 00:00:00 2001 From: kaiyan-sheng Date: Thu, 14 May 2020 14:59:55 -0600 Subject: [PATCH 1/4] [libbeat] Remove global loggers from plugin/cli --- libbeat/plugin/cli.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libbeat/plugin/cli.go b/libbeat/plugin/cli.go index 3111d149ea3f..046be737574c 100644 --- a/libbeat/plugin/cli.go +++ b/libbeat/plugin/cli.go @@ -30,6 +30,7 @@ import ( type pluginList struct { paths []string + logger *logp.Logger } func (p *pluginList) String() string { @@ -39,7 +40,7 @@ func (p *pluginList) String() string { func (p *pluginList) Set(v string) error { for _, path := range p.paths { if path == v { - logp.Warn("%s is already a registered plugin", path) + p.logger.Warnf("%s is already a registered plugin", path) return nil } } @@ -47,7 +48,9 @@ func (p *pluginList) Set(v string) error { return nil } -var plugins = &pluginList{} +var plugins = &pluginList{ + logger: logp.NewLogger("cli"), +} func init() { flag.Var(plugins, "plugin", "Load additional plugins") @@ -59,7 +62,7 @@ func Initialize() error { } for _, path := range plugins.paths { - logp.Info("loading plugin bundle: %v", path) + plugins.logger.Infof("loading plugin bundle: %v", path) if err := LoadPlugins(path); err != nil { return err From 8fa5a648babfd056205cd8b61d5eae4565ffd7c5 Mon Sep 17 00:00:00 2001 From: kaiyan-sheng Date: Thu, 14 May 2020 15:04:50 -0600 Subject: [PATCH 2/4] fix global logger in mockbeat --- libbeat/mock/mockbeat.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libbeat/mock/mockbeat.go b/libbeat/mock/mockbeat.go index 6224534c03be..f1b7f4e156fb 100644 --- a/libbeat/mock/mockbeat.go +++ b/libbeat/mock/mockbeat.go @@ -35,12 +35,14 @@ var Settings = instance.Settings{Name: Name, Version: Version, HasDashboards: tr type Mockbeat struct { done chan struct{} + logger *logp.Logger } // Creates beater func New(b *beat.Beat, _ *common.Config) (beat.Beater, error) { return &Mockbeat{ done: make(chan struct{}), + logger: logp.NewLogger("mockbeat"), }, nil } @@ -76,7 +78,7 @@ func (mb *Mockbeat) Run(b *beat.Beat) error { } func (mb *Mockbeat) Stop() { - logp.Info("Mockbeat Stop") + mb.logger.Info("Mockbeat Stop") close(mb.done) } From 2bd34f64b88d6f7a8f7aacc7ccd99b54b19e0a87 Mon Sep 17 00:00:00 2001 From: kaiyan-sheng Date: Fri, 15 May 2020 09:47:13 -0600 Subject: [PATCH 3/4] run mage fmt --- libbeat/mock/mockbeat.go | 4 ++-- libbeat/plugin/cli.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libbeat/mock/mockbeat.go b/libbeat/mock/mockbeat.go index f1b7f4e156fb..94d0996fd1a0 100644 --- a/libbeat/mock/mockbeat.go +++ b/libbeat/mock/mockbeat.go @@ -34,14 +34,14 @@ var Name = "mockbeat" var Settings = instance.Settings{Name: Name, Version: Version, HasDashboards: true} type Mockbeat struct { - done chan struct{} + done chan struct{} logger *logp.Logger } // Creates beater func New(b *beat.Beat, _ *common.Config) (beat.Beater, error) { return &Mockbeat{ - done: make(chan struct{}), + done: make(chan struct{}), logger: logp.NewLogger("mockbeat"), }, nil } diff --git a/libbeat/plugin/cli.go b/libbeat/plugin/cli.go index 046be737574c..221a163d064c 100644 --- a/libbeat/plugin/cli.go +++ b/libbeat/plugin/cli.go @@ -29,7 +29,7 @@ import ( ) type pluginList struct { - paths []string + paths []string logger *logp.Logger } From 7def7d537c32088f85a32f3855606407c07ac983 Mon Sep 17 00:00:00 2001 From: kaiyan-sheng Date: Tue, 19 May 2020 12:10:01 -0600 Subject: [PATCH 4/4] change logger name to mock --- libbeat/mock/mockbeat.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libbeat/mock/mockbeat.go b/libbeat/mock/mockbeat.go index 94d0996fd1a0..319b35083d35 100644 --- a/libbeat/mock/mockbeat.go +++ b/libbeat/mock/mockbeat.go @@ -42,7 +42,7 @@ type Mockbeat struct { func New(b *beat.Beat, _ *common.Config) (beat.Beater, error) { return &Mockbeat{ done: make(chan struct{}), - logger: logp.NewLogger("mockbeat"), + logger: logp.NewLogger("mock"), }, nil }