Skip to content

Commit

Permalink
Add logging to client command.
Browse files Browse the repository at this point in the history
  • Loading branch information
lthibault committed Apr 22, 2022
1 parent fe075d4 commit 60f4561
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
12 changes: 2 additions & 10 deletions internal/cmd/client/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package client
import (
"fmt"
"io"
"time"

"github.com/urfave/cli/v2"
"github.com/wetware/ww/pkg/client"
Expand Down Expand Up @@ -53,11 +52,6 @@ func publish() cli.ActionFunc {
return err
}

// FIXME: if we remove this, commands with sochastically hang.
// Best guess is that this happens when they are pipelined
// against a pending FutureTopic.
time.Sleep(time.Millisecond * 5)

return t.Publish(c.Context, b)
}
}
Expand All @@ -69,6 +63,8 @@ func subscribe() cli.ActionFunc {
msg []byte
)

logger.Debug("connected to cluster")

t := node.Join(c.Context, c.String("topic"))
defer t.Release()

Expand All @@ -87,10 +83,6 @@ func subscribe() cli.ActionFunc {
fmt.Fprintln(c.App.Writer, string(msg))
}

if err == client.ErrDisconnected {
err = nil
}

return err
}
}
10 changes: 6 additions & 4 deletions internal/cmd/client/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@ import (
)

var (
app *fx.App
node *client.Node
app *fx.App
node *client.Node
logger log.Logger
)

func setup() cli.BeforeFunc {
return func(c *cli.Context) error {
app = fx.New(fx.NopLogger,
fx.Supply(c),
fx.Populate(&logger),
fx.Provide(
localhost,
logger,
logging,
dialer),
fx.Invoke(dial))

Expand All @@ -50,7 +52,7 @@ func teardown() cli.AfterFunc {
}
}

func logger(c *cli.Context) log.Logger {
func logging(c *cli.Context) log.Logger {
return logutil.New(c).With(discoveryFields(c))
}

Expand Down

0 comments on commit 60f4561

Please sign in to comment.