mirror of
https://github.com/luxfi/netrunner.git
synced 2026-07-27 00:04:23 +00:00
pass log object to client
This commit is contained in:
+1
-20
@@ -14,7 +14,6 @@ import (
|
||||
|
||||
"github.com/ava-labs/avalanche-network-runner/local"
|
||||
"github.com/ava-labs/avalanche-network-runner/rpcpb"
|
||||
"github.com/ava-labs/avalanche-network-runner/utils/constants"
|
||||
"github.com/ava-labs/avalanchego/utils/logging"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
@@ -23,7 +22,6 @@ import (
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
LogLevel string
|
||||
Endpoint string
|
||||
DialTimeout time.Duration
|
||||
}
|
||||
@@ -63,24 +61,7 @@ type client struct {
|
||||
closeOnce sync.Once
|
||||
}
|
||||
|
||||
func New(cfg Config) (Client, error) {
|
||||
lvl, err := logging.ToLevel(cfg.LogLevel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
lcfg := logging.Config{
|
||||
DisplayLevel: lvl,
|
||||
// this will result in no written logs, just stdout
|
||||
// to enable log files, a logDir param should be added and
|
||||
// accordingly possibly a flag
|
||||
LogLevel: logging.Off,
|
||||
}
|
||||
logFactory := logging.NewFactory(lcfg)
|
||||
log, err := logFactory.Make(constants.LogNameClient)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func New(cfg Config, log logging.Logger) (Client, error) {
|
||||
log.Debug("dialing server at endpoint %s", cfg.Endpoint)
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), cfg.DialTimeout)
|
||||
|
||||
@@ -890,10 +890,9 @@ func getSnapshotNamesFunc(cmd *cobra.Command, args []string) error {
|
||||
|
||||
func newClient() (client.Client, error) {
|
||||
return client.New(client.Config{
|
||||
LogLevel: logLevel,
|
||||
Endpoint: endpoint,
|
||||
DialTimeout: dialTimeout,
|
||||
})
|
||||
}, log)
|
||||
}
|
||||
|
||||
func getAsyncContext() context.Context {
|
||||
|
||||
+1
-2
@@ -48,10 +48,9 @@ func pingFunc(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
cli, err := client.New(client.Config{
|
||||
LogLevel: logLevel,
|
||||
Endpoint: endpoint,
|
||||
DialTimeout: dialTimeout,
|
||||
})
|
||||
}, log)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -127,10 +127,9 @@ var _ = ginkgo.BeforeSuite(func() {
|
||||
gomega.Ω(err).Should(gomega.BeNil())
|
||||
|
||||
cli, err = client.New(client.Config{
|
||||
LogLevel: logLevel,
|
||||
Endpoint: gRPCEp,
|
||||
DialTimeout: 10 * time.Second,
|
||||
})
|
||||
}, log)
|
||||
gomega.Ω(err).Should(gomega.BeNil())
|
||||
})
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ package constants
|
||||
|
||||
const (
|
||||
LogNameMain = "main"
|
||||
LogNameClient = "client"
|
||||
LogNameControl = "control"
|
||||
LogNameTest = "test"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user