Skip to content

Commit

Permalink
[libbeat] Remove global loggers from plugin and mock (#18552)
Browse files Browse the repository at this point in the history
* [libbeat] Remove global loggers from plugin/cli
  • Loading branch information
kaiyan-sheng authored Jun 15, 2020
1 parent a655d2e commit 9a1b1d0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
8 changes: 5 additions & 3 deletions libbeat/mock/mockbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ 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("mock"),
}, nil
}

Expand Down Expand Up @@ -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)
}
11 changes: 7 additions & 4 deletions libbeat/plugin/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import (
)

type pluginList struct {
paths []string
paths []string
logger *logp.Logger
}

func (p *pluginList) String() string {
Expand All @@ -39,15 +40,17 @@ 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
}
}
p.paths = append(p.paths, v)
return nil
}

var plugins = &pluginList{}
var plugins = &pluginList{
logger: logp.NewLogger("cli"),
}

func init() {
flag.Var(plugins, "plugin", "Load additional plugins")
Expand All @@ -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
Expand Down

0 comments on commit 9a1b1d0

Please sign in to comment.