mirror of
https://github.com/mudler/LocalAI.git
synced 2025-05-20 10:35:01 +00:00
chore(p2p): enhance logging (#4090)
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
parent
06d0d00231
commit
20a5b20b59
2 changed files with 27 additions and 8 deletions
|
@ -231,10 +231,14 @@ func discoveryTunnels(ctx context.Context, n *node.Node, token, servicesID strin
|
||||||
|
|
||||||
data := ledger.LastBlock().Storage[servicesID]
|
data := ledger.LastBlock().Storage[servicesID]
|
||||||
|
|
||||||
zlog.Debug().Any("data", ledger.LastBlock().Storage).Msg("Ledger data")
|
if logLevel == logLevelDebug {
|
||||||
|
// We want to surface this debugging data only if p2p logging is set to debug
|
||||||
|
// (and not generally the whole application, as this can be really noisy)
|
||||||
|
zlog.Debug().Any("data", ledger.LastBlock().Storage).Msg("Ledger data")
|
||||||
|
}
|
||||||
|
|
||||||
for k, v := range 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{}
|
nd := &NodeData{}
|
||||||
if err := v.Unmarshal(nd); err != nil {
|
if err := v.Unmarshal(nd); err != nil {
|
||||||
zlog.Error().Msg("cannot unmarshal node data")
|
zlog.Error().Msg("cannot unmarshal node data")
|
||||||
|
@ -269,7 +273,7 @@ func ensureService(ctx context.Context, n *node.Node, nd *NodeData, sserv string
|
||||||
if ndService, found := service[nd.Name]; !found {
|
if ndService, found := service[nd.Name]; !found {
|
||||||
if !nd.IsOnline() {
|
if !nd.IsOnline() {
|
||||||
// if node is offline and not present, do nothing
|
// if node is offline and not present, do nothing
|
||||||
zlog.Debug().Msgf("Node %s is offline", nd.ID)
|
// Node nd.ID is offline
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -381,10 +385,6 @@ func newNodeOpts(token string) ([]node.Option, error) {
|
||||||
noDHT := os.Getenv("LOCALAI_P2P_DISABLE_DHT") == "true"
|
noDHT := os.Getenv("LOCALAI_P2P_DISABLE_DHT") == "true"
|
||||||
noLimits := os.Getenv("LOCALAI_P2P_ENABLE_LIMITS") == "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")
|
libp2ploglevel := os.Getenv("LOCALAI_LIBP2P_LOGLEVEL")
|
||||||
if libp2ploglevel == "" {
|
if libp2ploglevel == "" {
|
||||||
libp2ploglevel = "fatal"
|
libp2ploglevel = "fatal"
|
||||||
|
@ -396,7 +396,7 @@ func newNodeOpts(token string) ([]node.Option, error) {
|
||||||
},
|
},
|
||||||
NetworkToken: token,
|
NetworkToken: token,
|
||||||
LowProfile: false,
|
LowProfile: false,
|
||||||
LogLevel: loglevel,
|
LogLevel: logLevel,
|
||||||
Libp2pLogLevel: libp2ploglevel,
|
Libp2pLogLevel: libp2ploglevel,
|
||||||
Ledger: config.Ledger{
|
Ledger: config.Ledger{
|
||||||
SyncInterval: defaultInterval,
|
SyncInterval: defaultInterval,
|
||||||
|
|
19
core/p2p/p2p_common.go
Normal file
19
core/p2p/p2p_common.go
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
package p2p
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var logLevel = strings.ToLower(os.Getenv("LOCALAI_P2P_LOGLEVEL"))
|
||||||
|
|
||||||
|
const (
|
||||||
|
logLevelDebug = "debug"
|
||||||
|
logLevelInfo = "info"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
if logLevel == "" {
|
||||||
|
logLevel = logLevelInfo
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue