pass log object to client

This commit is contained in:
Fabio Barone
2022-08-10 18:21:54 -05:00
parent 6f630eba0c
commit 5cb8e740a8
5 changed files with 4 additions and 27 deletions
+1 -20
View File
@@ -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)
+1 -2
View File
@@ -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
View File
@@ -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
}
+1 -2
View File
@@ -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())
})
-1
View File
@@ -4,7 +4,6 @@ package constants
const (
LogNameMain = "main"
LogNameClient = "client"
LogNameControl = "control"
LogNameTest = "test"
)