Skip to content

Commit

Permalink
add trace logging for delve server logs
Browse files Browse the repository at this point in the history
  • Loading branch information
runz0rd committed Aug 3, 2022
1 parent 2033ec0 commit 02d1dd5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion delve/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (kds KubeDelveServer) Port() int {

func NewKubeDelveServer(l *logrus.Entry, namespace, host string, port int) *KubeDelveServer {
kubectl := exec.NewKubectlCommand()
kubectl.Logger(l).Args("-n", namespace)
kubectl.Logger(l).Quiet().Args("-n", namespace)
return &KubeDelveServer{host, port, kubectl, nil}
}

Expand Down
16 changes: 12 additions & 4 deletions exec/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,20 @@ import (
)

type Cmd struct {
l *logrus.Entry
// actual *exec.Cmd
l *logrus.Entry
command []string
cwd string
env []string
stdin io.Reader
stdoutWriters []io.Writer
stderrWriters []io.Writer
wait bool
// t time.Duration
preStartFunc func() error
postStartFunc func(p *os.Process) error
postEndFunc func() error
chanStarted chan struct{}
chanDone chan struct{}
quiet bool
}

func NewCommand(name string) *Cmd {
Expand Down Expand Up @@ -108,6 +107,11 @@ func (c *Cmd) Logger(l *logrus.Entry) *Cmd {
return c
}

func (c *Cmd) Quiet() *Cmd {
c.quiet = true
return c
}

func (c *Cmd) Run(ctx context.Context) (string, error) {
return c.run(goexec.CommandContext(ctx, c.command[0], c.command[1:]...))
}
Expand All @@ -132,7 +136,11 @@ func (c *Cmd) run(cmd *goexec.Cmd) (string, error) {
if c.l != nil {
c.l.Tracef("executing %q in %q", cmd.String(), cmd.Dir)
c.stdoutWriters = append(c.stdoutWriters, c.l.WriterLevel(logrus.TraceLevel))
c.stderrWriters = append(c.stderrWriters, c.l.WriterLevel(logrus.WarnLevel))
if c.quiet {
c.stderrWriters = append(c.stderrWriters, c.l.WriterLevel(logrus.TraceLevel))
} else {
c.stderrWriters = append(c.stderrWriters, c.l.WriterLevel(logrus.WarnLevel))
}
}
cmd.Stdout = io.MultiWriter(c.stdoutWriters...)
cmd.Stderr = io.MultiWriter(c.stderrWriters...)
Expand Down

0 comments on commit 02d1dd5

Please sign in to comment.