Skip to content

Commit

Permalink
Merge pull request #106 from philippseith/feature/client_logging_on_e…
Browse files Browse the repository at this point in the history
…rror

chg: improve logging
  • Loading branch information
philippseith authored Nov 22, 2021
2 parents d8ee60f + 4e781bd commit 8abe006
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ func NewClient(ctx context.Context, options ...func(Party) error) (Client, error
}
}
}
// Wrap logging with timestamps
info, dbg = c.loggers()
c.setLoggers(
log.WithPrefix(info, "ts", log.DefaultTimestampUTC),
log.WithPrefix(dbg, "ts", log.DefaultTimestampUTC),
)
if c.conn == nil && c.connectionFactory == nil {
return nil, errors.New("neither WithConnection nor WithAutoReconnect option was given")
}
Expand Down Expand Up @@ -140,6 +146,7 @@ func (c *client) Start() {
// RUN!
err := c.run()
if err != nil {
_ = c.info.Log("connect", fmt.Sprintf("%v", err))
c.setErr(err)
}
shouldEnd := c.shouldClientEnd()
Expand Down Expand Up @@ -249,6 +256,7 @@ func (c *client) setState(state ClientState) {
c.mx.Lock()
defer c.mx.Unlock()
c.state = state
_ = c.dbg.Log("state", state)
for _, ch := range c.stateChangeChans {
go func(ch chan struct{}) {
c.mx.Lock()
Expand Down
2 changes: 1 addition & 1 deletion httpconnection.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func NewHTTPConnection(ctx context.Context, address string, options ...func(*htt
defer func() { _ = resp.Body.Close() }()

if resp.StatusCode != 200 {
return nil, fmt.Errorf("%v -> %v", req, resp.Status)
return nil, fmt.Errorf("%v %v -> %v", req.Method, req.URL.String(), resp.Status)
}

body, err := io.ReadAll(resp.Body)
Expand Down

0 comments on commit 8abe006

Please sign in to comment.