Skip to content

Commit

Permalink
chore(p2p): enhance logging
Browse files Browse the repository at this point in the history
Signed-off-by: Ettore Di Giacinto <[email protected]>
  • Loading branch information
mudler committed Nov 7, 2024
1 parent 06d0d00 commit 84fdca2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
12 changes: 5 additions & 7 deletions core/p2p/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,12 @@ func discoveryTunnels(ctx context.Context, n *node.Node, token, servicesID strin

data := ledger.LastBlock().Storage[servicesID]

zlog.Debug().Any("data", ledger.LastBlock().Storage).Msg("Ledger data")
if loglevel == "debug" {
zlog.Debug().Any("data", ledger.LastBlock().Storage).Msg("Ledger data")
}

for k, v := range data {
zlog.Debug().Msgf("New worker found in the ledger data '%s'", k)
// New worker found in the ledger data as k (worker id)
nd := &NodeData{}
if err := v.Unmarshal(nd); err != nil {
zlog.Error().Msg("cannot unmarshal node data")
Expand Down Expand Up @@ -269,7 +271,7 @@ func ensureService(ctx context.Context, n *node.Node, nd *NodeData, sserv string
if ndService, found := service[nd.Name]; !found {
if !nd.IsOnline() {
// if node is offline and not present, do nothing
zlog.Debug().Msgf("Node %s is offline", nd.ID)
// Node nd.ID is offline
return
}

Expand Down Expand Up @@ -381,10 +383,6 @@ func newNodeOpts(token string) ([]node.Option, error) {
noDHT := os.Getenv("LOCALAI_P2P_DISABLE_DHT") == "true"
noLimits := os.Getenv("LOCALAI_P2P_ENABLE_LIMITS") == "true"

loglevel := os.Getenv("LOCALAI_P2P_LOGLEVEL")
if loglevel == "" {
loglevel = "info"
}
libp2ploglevel := os.Getenv("LOCALAI_LIBP2P_LOGLEVEL")
if libp2ploglevel == "" {
libp2ploglevel = "fatal"
Expand Down
11 changes: 11 additions & 0 deletions core/p2p/p2p_common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package p2p

import "os"

var loglevel = os.Getenv("LOCALAI_P2P_LOGLEVEL")

func init() {
if loglevel == "" {
loglevel = "info"
}
}

0 comments on commit 84fdca2

Please sign in to comment.