From 44b6a86bfa1f2657c46d467568c81406703b5b63 Mon Sep 17 00:00:00 2001 From: ocnc-two Date: Sun, 25 Aug 2024 06:21:40 +0300 Subject: [PATCH] fix logger cli --- beacond/cmd/main.go | 1 - mod/cli/pkg/components/logger.go | 3 +- mod/node-core/pkg/builder/builder.go | 16 +++++----- mod/node-core/pkg/builder/invokers.go | 43 --------------------------- 4 files changed, 11 insertions(+), 52 deletions(-) delete mode 100644 mod/node-core/pkg/builder/invokers.go diff --git a/beacond/cmd/main.go b/beacond/cmd/main.go index a318b92eef..d30d80302a 100644 --- a/beacond/cmd/main.go +++ b/beacond/cmd/main.go @@ -65,7 +65,6 @@ func run() error { clicomponents.DefaultClientComponents(), // TODO: remove these, and eventually pull cfg and chainspec // from built node - nodecomponents.ProvideConfig, nodecomponents.ProvideChainSpec, ), ), diff --git a/mod/cli/pkg/components/logger.go b/mod/cli/pkg/components/logger.go index 9ce2fef438..29ffc2196e 100644 --- a/mod/cli/pkg/components/logger.go +++ b/mod/cli/pkg/components/logger.go @@ -30,7 +30,6 @@ import ( type LoggerInput struct { depinject.In - Out io.Writer } @@ -39,6 +38,8 @@ type LoggerInput struct { func ProvideLogger( in LoggerInput, ) *phuslu.Logger { + // the logger config should be passed in here, but it is not yet populated + // so we pass in nil for now to get the default logger. logger := phuslu.NewLogger(in.Out, nil) logger.AddKeyColor("error", log.Red) logger.AddKeyColor("err", log.Red) diff --git a/mod/node-core/pkg/builder/builder.go b/mod/node-core/pkg/builder/builder.go index 311d62304d..317f3bb6d4 100644 --- a/mod/node-core/pkg/builder/builder.go +++ b/mod/node-core/pkg/builder/builder.go @@ -26,6 +26,7 @@ import ( "cosmossdk.io/depinject" sdklog "cosmossdk.io/log" servertypes "github.com/berachain/beacon-kit/mod/cli/pkg/commands/server/types" + "github.com/berachain/beacon-kit/mod/config" cometbft "github.com/berachain/beacon-kit/mod/consensus/pkg/cometbft/service" "github.com/berachain/beacon-kit/mod/log" "github.com/berachain/beacon-kit/mod/node-core/pkg/types" @@ -72,7 +73,7 @@ func New[ // build a new instance of the node. // It is necessary to adhere to the types.AppCreator[T] interface. func (nb *NodeBuilder[NodeT, LoggerT, LoggerConfigT]) Build( - logger sdklog.Logger, + sdklogger sdklog.Logger, db dbm.DB, _ io.Writer, cmtCfg *cmtcfg.Config, @@ -85,6 +86,8 @@ func (nb *NodeBuilder[NodeT, LoggerT, LoggerConfigT]) Build( } beaconNode NodeT cmtService *cometbft.Service + config *config.Config + logger = sdklogger.Impl().(LoggerT) ) // build all node components using depinject @@ -95,21 +98,20 @@ func (nb *NodeBuilder[NodeT, LoggerT, LoggerConfigT]) Build( ), depinject.Supply( appOpts, - logger.Impl().(LoggerT), + logger, db, cmtCfg, ), - // TODO: cosmos depinject bad project, fixed with dig. - // depinject.Invoke( - // SetLoggerConfig[LoggerT, LoggerConfigT], - // ), ), - &beaconNode, &apiBackend, + &beaconNode, &cmtService, + &config, ); err != nil { panic(err) } + // attach the logger config + logger.WithConfig(any(config.GetLogger()).(LoggerConfigT)) if apiBackend == nil { panic("node or api backend is nil") diff --git a/mod/node-core/pkg/builder/invokers.go b/mod/node-core/pkg/builder/invokers.go deleted file mode 100644 index f8cb2d1a49..0000000000 --- a/mod/node-core/pkg/builder/invokers.go +++ /dev/null @@ -1,43 +0,0 @@ -// SPDX-License-Identifier: BUSL-1.1 -// -// Copyright (C) 2024, Berachain Foundation. All rights reserved. -// Use of this software is governed by the Business Source License included -// in the LICENSE file of this repository and at www.mariadb.com/bsl11. -// -// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY -// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER -// VERSIONS OF THE LICENSED WORK. -// -// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF -// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF -// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE). -// -// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON -// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, -// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND -// TITLE. - -package builder - -import ( - "github.com/berachain/beacon-kit/mod/config" - "github.com/berachain/beacon-kit/mod/log" -) - -// SetLoggerConfig sets the logger configuration. It acts as an invoker -// for the depinject framework. -func SetLoggerConfig[ - LoggerT interface { - log.AdvancedLogger[LoggerT] - log.Configurable[LoggerT, LoggerConfigT] - }, - LoggerConfigT any, -]( - config *config.Config, - logger LoggerT, -) { - logger.WithConfig( - any(config.GetLogger()).(LoggerConfigT), - ) -}