Skip to content

Commit

Permalink
Merge pull request #626 from iotaledger/feat/reactive-logger
Browse files Browse the repository at this point in the history
Use reactive logger
  • Loading branch information
muXxer authored Dec 14, 2023
2 parents 7bc9088 + 751c9dc commit 36f1630
Show file tree
Hide file tree
Showing 39 changed files with 282 additions and 328 deletions.
2 changes: 1 addition & 1 deletion components/dashboard_metrics/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func configure() error {
}

func run() error {
Component.Logger().Infof("Starting %s ...", Component.Name)
Component.Logger.LogInfof("Starting %s ...", Component.Name)
if err := Component.Daemon().BackgroundWorker("DashboardMetricsUpdater", func(ctx context.Context) {
// Do not block until the Ticker is shutdown because we might want to start multiple Tickers and we can
// safely ignore the last execution when shutting down.
Expand Down
2 changes: 1 addition & 1 deletion components/inx/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func provide(c *dig.Container) error {
if err := c.Provide(func() *Server {
return newServer()
}); err != nil {
Component.LogPanic(err)
Component.LogPanic(err.Error())
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions components/inx/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ func (s *Server) Start() {
go func() {
listener, err := net.Listen("tcp", ParamsINX.BindAddress)
if err != nil {
Component.LogFatalfAndExit("failed to listen: %v", err)
Component.LogFatalf("failed to listen: %v", err)
}
defer listener.Close()

if err := s.grpcServer.Serve(listener); err != nil {
Component.LogFatalfAndExit("failed to serve: %v", err)
Component.LogFatalf("failed to serve: %v", err)
}
}()
}
Expand Down
2 changes: 1 addition & 1 deletion components/metrics/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func run() error {
//nolint:contextcheck // false positive
err := server.Shutdown(shutdownCtx)
if err != nil {
Component.LogWarn(err)
Component.LogWarn(err.Error())
}

Component.LogInfo("Stopping Prometheus exporter ... done")
Expand Down
2 changes: 1 addition & 1 deletion components/metricstracker/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func provide(c *dig.Container) error {

return m
}); err != nil {
Component.LogPanic(err)
Component.LogPanic(err.Error())
}

return nil
Expand Down
32 changes: 16 additions & 16 deletions components/p2p/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func initConfigParams(c *dig.Container) error {
P2PBindMultiAddresses: ParamsP2P.BindMultiAddresses,
}
}); err != nil {
Component.LogPanic(err)
Component.LogPanic(err.Error())
}

return nil
Expand All @@ -86,7 +86,7 @@ func provide(c *dig.Container) error {
}

if err := c.Provide(func(deps manualPeeringDeps) *manualpeering.Manager {
return manualpeering.NewManager(deps.P2PManager, Component.WorkerPool, Component.Logger())
return manualpeering.NewManager(deps.P2PManager, Component.WorkerPool, Component.Logger)
}); err != nil {
return err
}
Expand All @@ -103,21 +103,21 @@ func provide(c *dig.Container) error {
if err := c.Provide(func(deps autoPeeringDeps) *autopeering.Manager {
peersMultiAddresses, err := getMultiAddrsFromString(ParamsPeers.BootstrapPeers)
if err != nil {
Component.LogErrorfAndExit("Failed to parse bootstrapPeers param: %s", err)
Component.LogFatalf("Failed to parse bootstrapPeers param: %s", err)
}

for _, multiAddr := range peersMultiAddresses {
bootstrapPeer, err := network.NewPeerFromMultiAddr(multiAddr)
if err != nil {
Component.LogErrorfAndExit("Failed to parse bootstrap peer multiaddress: %s", err)
Component.LogFatalf("Failed to parse bootstrap peer multiaddress: %s", err)
}

if err := deps.PeerDB.UpdatePeer(bootstrapPeer); err != nil {
Component.LogErrorf("Failed to update bootstrap peer: %s", err)
}
}

return autopeering.NewManager(deps.Protocol.LatestAPI().ProtocolParameters().NetworkName(), deps.P2PManager, deps.Host, deps.PeerDB, Component.Logger())
return autopeering.NewManager(deps.Protocol.LatestAPI().ProtocolParameters().NetworkName(), deps.P2PManager, deps.Host, deps.PeerDB, Component.Logger)
}); err != nil {
return err
}
Expand All @@ -132,7 +132,7 @@ func provide(c *dig.Container) error {
if err := c.Provide(func() peerDatabaseResult {
peerDB, peerDBKVStore, err := initPeerDB()
if err != nil {
Component.LogFatalAndExit(err)
Component.LogFatal(err.Error())
}

return peerDatabaseResult{
Expand Down Expand Up @@ -184,7 +184,7 @@ func provide(c *dig.Container) error {

peersMultiAddresses, err := getMultiAddrsFromString(ParamsPeers.Peers)
if err != nil {
Component.LogErrorAndExit(err)
Component.LogFatal(err.Error())
}

peerAdded := false
Expand All @@ -211,7 +211,7 @@ func provide(c *dig.Container) error {

return p2pConfigManager
}); err != nil {
Component.LogPanic(err)
Component.LogPanic(err.Error())
}

type p2pDeps struct {
Expand All @@ -238,7 +238,7 @@ func provide(c *dig.Container) error {
// load up the previously generated identity or create a new one
nodePrivateKey, newlyCreated, err := hivep2p.LoadOrCreateIdentityPrivateKey(privKeyFilePath, ParamsP2P.IdentityPrivateKey)
if err != nil {
Component.LogPanic(err)
Component.LogPanic(err.Error())
}
res.NodePrivateKey = nodePrivateKey

Expand Down Expand Up @@ -283,19 +283,19 @@ func provide(c *dig.Container) error {
}()),
)
if err != nil {
Component.LogFatalfAndExit("unable to initialize libp2p host: %s", err)
Component.LogFatalf("unable to initialize libp2p host: %s", err)
}
res.Host = createdHost

Component.LogInfof("Initialized P2P host %s %s", createdHost.ID().String(), createdHost.Addrs())

return res
}); err != nil {
Component.LogPanic(err)
Component.LogPanic(err.Error())
}

return c.Provide(func(host host.Host, peerDB *network.DB) *p2p.Manager {
return p2p.NewManager(host, peerDB, Component.Logger())
return p2p.NewManager(host, peerDB, Component.Logger)
})
}

Expand Down Expand Up @@ -336,7 +336,7 @@ func run() error {
if err := Component.Daemon().BackgroundWorker(Component.Name, func(ctx context.Context) {
deps.ManualPeeringMgr.Start()
if err := deps.AutoPeeringMgr.Start(ctx); err != nil {
Component.LogErrorAndExit("Failed to start autopeering manager: %s", err)
Component.LogFatalf("Failed to start autopeering manager: %s", err)
}

defer func() {
Expand All @@ -348,20 +348,20 @@ func run() error {
connectConfigKnownPeers()
<-ctx.Done()
}, daemon.PriorityManualPeering); err != nil {
Component.LogErrorfAndExit("Failed to start as daemon: %s", err)
Component.LogFatalf("Failed to start as daemon: %s", err)
}

if err := Component.Daemon().BackgroundWorker(fmt.Sprintf("%s-P2PManager", Component.Name), func(ctx context.Context) {
defer deps.P2PManager.Shutdown()
defer func() {
if err := deps.P2PManager.P2PHost().Close(); err != nil {
Component.LogWarn("Failed to close libp2p host: %+v", err)
Component.LogWarnf("Failed to close libp2p host: %+v", err)
}
}()

<-ctx.Done()
}, daemon.PriorityP2P); err != nil {
Component.LogErrorfAndExit("Failed to start as daemon: %s", err)
Component.LogFatalf("Failed to start as daemon: %s", err)
}

return nil
Expand Down
9 changes: 4 additions & 5 deletions components/protocol/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/iotaledger/hive.go/app"
"github.com/iotaledger/hive.go/ierrors"
hivedb "github.com/iotaledger/hive.go/kvstore/database"
"github.com/iotaledger/hive.go/log"
"github.com/iotaledger/hive.go/runtime/workerpool"
"github.com/iotaledger/iota-core/pkg/core/account"
"github.com/iotaledger/iota-core/pkg/daemon"
Expand Down Expand Up @@ -104,7 +103,7 @@ func initConfigParams(c *dig.Container) error {
if err := c.Provide(func() cfgResult {
dbEngine, err := hivedb.EngineFromStringAllowed(ParamsDatabase.Engine, database.AllowedEnginesDefault)
if err != nil {
Component.LogPanic(err)
Component.LogPanic(err.Error())
}

return cfgResult{
Expand All @@ -113,7 +112,7 @@ func initConfigParams(c *dig.Container) error {
ProtocolParameters: readProtocolParameters(),
}
}); err != nil {
Component.LogPanic(err)
Component.LogPanic(err.Error())
}

return nil
Expand All @@ -140,7 +139,7 @@ func provide(c *dig.Container) error {
}

return protocol.New(
log.NewLogger("node"),
Component.Logger,
workerpool.NewGroup("Protocol"),
deps.P2PManager,
protocol.WithBaseDirectory(ParamsDatabase.Path),
Expand Down Expand Up @@ -309,7 +308,7 @@ func run() error {
return Component.Daemon().BackgroundWorker(Component.Name, func(ctx context.Context) {
if err := deps.Protocol.Run(ctx); err != nil {
if !ierrors.Is(err, context.Canceled) {
Component.LogErrorfAndExit("Error running the Protocol: %s", err.Error())
Component.LogFatal("Error running the Protocol: %s", err.Error())
}
}

Expand Down
6 changes: 3 additions & 3 deletions components/restapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ func apiMiddleware() echo.MiddlewareFunc {

publicRoutesRegEx, err := restapi.CompileRoutesAsRegexes(ParamsRestAPI.PublicRoutes)
if err != nil {
Component.LogErrorfAndExit(err.Error())
Component.LogFatal(err.Error())
}

protectedRoutesRegEx, err := restapi.CompileRoutesAsRegexes(ParamsRestAPI.ProtectedRoutes)
if err != nil {
Component.LogErrorfAndExit(err.Error())
Component.LogFatal(err.Error())
}

matchPublic := func(c echo.Context) bool {
Expand Down Expand Up @@ -48,7 +48,7 @@ func apiMiddleware() echo.MiddlewareFunc {
// configure JWT auth
salt := ParamsRestAPI.JWTAuth.Salt
if len(salt) == 0 {
Component.LogErrorfAndExit("'%s' should not be empty", Component.App().Config().GetParameterPath(&(ParamsRestAPI.JWTAuth.Salt)))
Component.LogFatalf("'%s' should not be empty", Component.App().Config().GetParameterPath(&(ParamsRestAPI.JWTAuth.Salt)))
}

// API tokens do not expire.
Expand Down
12 changes: 6 additions & 6 deletions components/restapi/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func initConfigParams(c *dig.Container) error {
RestAPILimitsMaxResults: ParamsRestAPI.Limits.MaxResults,
}
}); err != nil {
Component.LogPanic(err)
Component.LogPanic(err.Error())
}

return nil
Expand All @@ -76,7 +76,7 @@ func initConfigParams(c *dig.Container) error {
func provide(c *dig.Container) error {
if err := c.Provide(func() *echo.Echo {
e := httpserver.NewEcho(
Component.Logger(),
Component.Logger,
nil,
ParamsRestAPI.DebugRequestLoggerEnabled,
)
Expand All @@ -86,7 +86,7 @@ func provide(c *dig.Container) error {

return e
}); err != nil {
Component.LogPanic(err)
Component.LogPanic(err.Error())
}

type proxyDeps struct {
Expand All @@ -97,13 +97,13 @@ func provide(c *dig.Container) error {
if err := c.Provide(func(deps proxyDeps) *restapi.RestRouteManager {
return restapi.NewRestRouteManager(deps.Echo)
}); err != nil {
Component.LogPanic(err)
Component.LogPanic(err.Error())
}

if err := c.Provide(func(deps dependencies) *blockhandler.BlockHandler {
return blockhandler.New(deps.Protocol)
}); err != nil {
Component.LogPanic(err)
Component.LogPanic(err.Error())
}

return nil
Expand Down Expand Up @@ -144,7 +144,7 @@ func run() error {

//nolint:contextcheck // false positive
if err := deps.Echo.Shutdown(shutdownCtx); err != nil {
Component.LogWarn(err)
Component.LogWarn(err.Error())
}

Component.LogInfo("Stopping REST-API server ... done")
Expand Down
2 changes: 1 addition & 1 deletion components/restapi/management/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func configure() error {
})

routeGroup.POST(api.ManagementEndpointPeers, func(c echo.Context) error {
resp, err := addPeer(c, Component.Logger())
resp, err := addPeer(c, Component.Logger)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions components/restapi/management/peers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package management
import (
"github.com/labstack/echo/v4"

"github.com/iotaledger/hive.go/logger"
"github.com/iotaledger/hive.go/log"
"github.com/iotaledger/iota.go/v4/api"
)

Expand Down Expand Up @@ -89,7 +89,7 @@ func listPeers(_ echo.Context) (*api.PeersResponse, error) {
return nil, nil
}

func addPeer(_ echo.Context, _ *logger.Logger) (*api.PeerInfo, error) {
func addPeer(_ echo.Context, _ log.Logger) (*api.PeerInfo, error) {
/*
request := &addPeerRequest{}
Expand Down
12 changes: 3 additions & 9 deletions config_defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,12 @@
}
},
"logger": {
"name": "",
"level": "info",
"disableCaller": true,
"disableStacktrace": false,
"stacktraceLevel": "panic",
"encoding": "console",
"encodingConfig": {
"timeEncoder": "rfc3339"
},
"timeFormat": "rfc3339",
"outputPaths": [
"stdout"
],
"disableEvents": true
]
},
"p2p": {
"bindMultiAddresses": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ services:
-c
config.json
--logger.level=debug
--logger.disableCaller=false
--p2p.peers=/dns/node-01.feature/tcp/14666/p2p/12D3KooWCrjmh4dUCWfGVQT6ivzArieJB9Z3eKdy2mdEEN95NDPS
--p2p.externalMultiAddresses={{ ips | join(',') }}
--p2p.identityPrivateKey={{p2pIdentityPrvKey}}
Expand Down
Loading

0 comments on commit 36f1630

Please sign in to comment.