Skip to content

Commit

Permalink
Set diagnsotic for main
Browse files Browse the repository at this point in the history
  • Loading branch information
desa committed Sep 20, 2017
1 parent 5d228b2 commit 0f81ade
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion cmd/kapacitord/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/influxdata/kapacitor/cmd/kapacitord/help"
"github.com/influxdata/kapacitor/cmd/kapacitord/run"
"github.com/influxdata/kapacitor/services/diagnostic"
)

type Diagnostic run.Diagnostic
Expand Down Expand Up @@ -56,6 +57,7 @@ type Main struct {
// NewMain return a new instance of Main.
func NewMain() *Main {
return &Main{
Diag: diagnostic.BootstrapMainHandler(),
Stdin: os.Stdin,
Stdout: os.Stdout,
Stderr: os.Stderr,
Expand All @@ -77,7 +79,7 @@ func (m *Main) Run(args ...string) error {
cmd.Branch = branch

err := cmd.Run(args...)
// Use logger from cmd since it may have special config now.
// Use diagnostic from cmd since it may have special config now.
if cmd.Diag != nil {
m.Diag = cmd.Diag
}
Expand Down
4 changes: 3 additions & 1 deletion cmd/kapacitord/run/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ func (cmd *Command) Run(args ...string) error {

// Initialize Logging Services
cmd.diagService = diagnostic.NewService(config.Logging, cmd.Stdout, cmd.Stderr)
cmd.diagService.Open()
if err := cmd.diagService.Open(); err != nil {
return fmt.Errorf("failed to opend diagnostic service: %v", err)
}

// Initialize cmd diagnostic
cmd.Diag = cmd.diagService.NewCmdHandler()
Expand Down
8 changes: 8 additions & 0 deletions services/diagnostic/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ func NewService(c Config, stdout, stderr io.Writer) *Service {
}
}

func BootstrapMainHandler() *CmdHandler {
s := NewService(NewConfig(), nil, os.Stderr)
// Should never error
_ = s.Open()

return s.NewCmdHandler()
}

func (s *Service) SetLogLevelFromName(lvl string) error {
s.mu.Lock()
defer s.mu.Unlock()
Expand Down

0 comments on commit 0f81ade

Please sign in to comment.