Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry-pick #18552 to 7.x: [libbeat] Remove global loggers from plugin and mock #19203

Merged
merged 1 commit into from
Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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