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

update logrus to 1.0, use Entry.Writer to catch exec stdout #425

Merged
merged 1 commit into from
Jul 5, 2017
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: 2 additions & 6 deletions backends/backends.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,8 @@ func (b *Backend) PollAction() {
}
}

// PollStop closes the Backends logs
func (b *Backend) PollStop() {
if b.onChangeCmd != nil {
b.onChangeCmd.CloseLogs()
}
}
// PollStop is a no-op
func (b *Backend) PollStop() {}

// CheckForUpstreamChanges checks the service discovery endpoint for any changes
// in a dependent backend. Returns true when there has been a change.
Expand Down
25 changes: 9 additions & 16 deletions commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package commands
import (
"errors"
"fmt"
"io"
"os"
"os/exec"
"strings"
Expand All @@ -25,8 +24,7 @@ type Command struct {
Timeout string
TimeoutDuration time.Duration
ticker *time.Ticker
logger io.WriteCloser
logFields log.Fields
logger *log.Entry
}

// NewCommand parses JSON config into a Command
Expand All @@ -45,9 +43,11 @@ func NewCommand(rawArgs interface{}, timeoutFmt string, fields log.Fields) (*Com
Args: args,
Timeout: timeoutFmt,
TimeoutDuration: timeout,
logger: log.StandardLogger().Writer(),
logFields: fields,
} // Cmd and ticker all created at RunAndWait or RunWithTimeout

if fields != nil {
cmd.logger = log.WithFields(fields)
}
return cmd, nil
}

Expand All @@ -73,7 +73,7 @@ func RunAndWait(c *Command) (int, error) {
}
log.Debugf("%s.RunAndWait start", c.Name)
c.setUpCmd()
if c.logFields == nil {
if c.logger == nil {
c.Cmd.Stdout = os.Stdout
c.Cmd.Stderr = os.Stderr
}
Expand Down Expand Up @@ -169,11 +169,11 @@ func RunWithTimeout(c *Command) error {
func (c *Command) setUpCmd() {
cmd := ArgsToCmd(c.Exec, c.Args)
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
if c.logFields == nil {
if c.logger == nil {
cmd.Stderr = os.Stderr
} else {
cmd.Stdout = c.logger
cmd.Stderr = c.logger
cmd.Stdout = c.logger.Writer()
cmd.Stderr = c.logger.Writer()
}
c.Cmd = cmd
}
Expand Down Expand Up @@ -249,10 +249,3 @@ func (c *Command) waitForTimeout() error {
log.Debugf("%s.run complete", c.Name)
return nil
}

// CloseLogs closes logs, duh
func (c *Command) CloseLogs() {
if c.logger != nil {
c.logger.Close()
}
}
1 change: 0 additions & 1 deletion coprocesses/coprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,5 @@ func (c *Coprocess) Stop() {
c.restart = false
if c.cmd != nil {
c.cmd.Kill()
c.cmd.CloseLogs()
}
}
8 changes: 4 additions & 4 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ homepage: https://www.joyent.com/containerpilot
license: MPL-2.0
import:
- package: github.com/Sirupsen/logrus
version: ~0.9.0
version: 1.0.0
- package: github.com/beorn7/perks
version: b965b613227fddccbfffe13eae360ed3fa822f8d
subpackages:
Expand Down
8 changes: 2 additions & 6 deletions services/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,8 @@ func (s *Service) PollAction() {
}
}

// PollStop closes the Service's logs
func (s *Service) PollStop() {
if s.healthCheckCmd != nil {
s.healthCheckCmd.CloseLogs()
}
}
// PollStop is a no-op
func (s *Service) PollStop() {}

// SendHeartbeat sends a heartbeat for this service
func (s *Service) SendHeartbeat() {
Expand Down
1 change: 0 additions & 1 deletion tasks/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ func (t *Task) PollStop() {
log.Debugf("task[%s].PollStop", t.Name)
if t.cmd != nil {
t.cmd.Kill()
t.cmd.CloseLogs()
}
}

Expand Down
8 changes: 2 additions & 6 deletions telemetry/sensors.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,8 @@ func (s *Sensor) PollAction() {
}
}

// PollStop closes the Sensor's logs
func (s *Sensor) PollStop() {
if s.checkCmd != nil {
s.checkCmd.CloseLogs()
}
}
// PollStop is a no-op
func (s *Sensor) PollStop() {}

// wrapping this func call makes it easier to test
func (s *Sensor) observe() (string, error) {
Expand Down