Skip to content

Commit

Permalink
Add ability to change logLevel
Browse files Browse the repository at this point in the history
  • Loading branch information
palkan committed Sep 12, 2021
1 parent c849495 commit 69705f7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ You can pass the following options to the `connect` method as the second argumen
tags: {}, // k6 tags
handshakeTimeoutS: 60, // Max allowed time to initialize a connection
receiveTimeoutMs: 1000, // Max time to wait for an incoming message
logLevel: "info" // logging level (change to debug to see more information)
}
```
Expand Down
9 changes: 9 additions & 0 deletions cable.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/dop251/goja"
"github.com/gorilla/websocket"
"github.com/sirupsen/logrus"
"go.k6.io/k6/js/common"
"go.k6.io/k6/js/modules"
"go.k6.io/k6/lib"
Expand Down Expand Up @@ -63,6 +64,14 @@ func (r *Cable) Connect(ctx context.Context, cableUrl string, opts goja.Value) (
}
}

level, err := logrus.ParseLevel(cOpts.LogLevel)

if err != nil {
panic(err)
}

state.Logger.SetLevel(level)

logger := state.Logger.WithField("source", "cable")

conn, httpResponse, connErr := wsd.DialContext(ctx, cableUrl, headers)
Expand Down
2 changes: 1 addition & 1 deletion channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (ch *Channel) ReceiveN(n int, cond goja.Value) []interface{} {
return results
}
case <-timer.C:
ch.logger.Error("receive timeout exceeded; consider increasing receiveTimeoutMs configuration option")
ch.logger.Warn("receive timeout exceeded; consider increasing receiveTimeoutMs configuration option")
return results
}
}
Expand Down
5 changes: 3 additions & 2 deletions connect_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ type connectOptions struct {
Tags map[string]string `json:"tags"`
Codec string `json:"codec"`

HandshakeTimeoutS int `json:"handshakeTimeoutS"`
ReceiveTimeoutMs int `json:"receiveTimeoutMs"`
HandshakeTimeoutS int `json:"handshakeTimeoutS"`
ReceiveTimeoutMs int `json:"receiveTimeoutMs"`
LogLevel string `json:"logLevel"`
}

const (
Expand Down

0 comments on commit 69705f7

Please sign in to comment.