Skip to content

Commit d834d8d

Browse files
authored
improve logging (dependabot#77)
1 parent 8f18d36 commit d834d8d

File tree

5 files changed

+22
-2
lines changed

5 files changed

+22
-2
lines changed

cmd/dependabot/internal/cmd/root.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"log"
45
"os"
56
"time"
67

@@ -44,6 +45,9 @@ func Execute() {
4445
}
4546

4647
func init() {
48+
log.SetFlags(log.Ldate | log.Ltime | log.LUTC)
49+
log.SetPrefix("cli | ")
50+
4751
rootCmd.PersistentFlags().StringVar(&updaterImage, "updater-image", "", "container image to use for the updater")
4852
rootCmd.PersistentFlags().StringVar(&proxyImage, "proxy-image", infra.ProxyImageName, "container image to use for the proxy")
4953
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require (
66
github.com/MakeNowJust/heredoc v1.0.0
77
github.com/docker/cli v23.0.1+incompatible
88
github.com/docker/docker v23.0.1+incompatible
9+
github.com/goware/prefixer v0.0.0-20160118172347-395022866408
910
github.com/moby/moby v23.0.1+incompatible
1011
github.com/moby/sys/signal v0.7.0
1112
github.com/spf13/cobra v1.6.1

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
2626
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
2727
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
2828
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
29+
github.com/goware/prefixer v0.0.0-20160118172347-395022866408 h1:Y9iQJfEqnN3/Nce9cOegemcy/9Ai5k3huT6E80F3zaw=
30+
github.com/goware/prefixer v0.0.0-20160118172347-395022866408/go.mod h1:PE1ycukgRPJ7bJ9a1fdfQ9j8i/cEcRAoLZzbxYpNB/s=
2931
github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc=
3032
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
3133
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=

internal/infra/proxy.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7+
"github.com/goware/prefixer"
8+
"io"
79
"math/rand"
810
"os"
911
"path"
@@ -154,7 +156,11 @@ func (p *Proxy) TailLogs(ctx context.Context, cli *client.Client) {
154156
return
155157
}
156158

157-
_, _ = stdcopy.StdCopy(os.Stdout, os.Stderr, out)
159+
r, w := io.Pipe()
160+
go func() {
161+
_, _ = io.Copy(os.Stderr, prefixer.New(r, "proxy | "))
162+
}()
163+
_, _ = stdcopy.StdCopy(w, w, out)
158164
}
159165

160166
func (p *Proxy) Close() error {

internal/infra/updater.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"context"
77
"encoding/json"
88
"fmt"
9+
"github.com/goware/prefixer"
910
"io"
1011
"os"
1112
"path"
@@ -231,10 +232,16 @@ func (u *Updater) RunUpdate(ctx context.Context, proxyURL string, apiPort int) e
231232
if err != nil {
232233
return fmt.Errorf("failed to start exec: %w", err)
233234
}
235+
236+
r, w := io.Pipe()
237+
go func() {
238+
_, _ = io.Copy(os.Stderr, prefixer.New(r, "updater | "))
239+
}()
240+
234241
// blocks until update is complete or ctl-c
235242
ch := make(chan struct{})
236243
go func() {
237-
_, _ = stdcopy.StdCopy(os.Stdout, os.Stderr, execResp.Reader)
244+
_, _ = stdcopy.StdCopy(w, w, execResp.Reader)
238245
ch <- struct{}{}
239246
}()
240247

0 commit comments

Comments
 (0)