From 2a6f91cd35fc55704badd6b297b82575b77df426 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Thu, 11 Jan 2018 18:09:10 +0100 Subject: [PATCH] Fix #240: Avoid duplicated list of facilities This puts some sanity in this. It's not super correct (name of facilities depend of the component and the main cluster component should not hard code them), but it's clear enough. Imho, better than over-engineering a more elegant approach. License: MIT Signed-off-by: Hector Sanjuan --- debug.go | 14 ++++---------- ipfs-cluster-service/main.go | 34 +++++----------------------------- logging.go | 36 ++++++++++++++++++++++++------------ nodebug.go | 13 ++++++------- silent.go | 8 +------- 5 files changed, 40 insertions(+), 65 deletions(-) diff --git a/debug.go b/debug.go index 0e7db654..f381763b 100644 --- a/debug.go +++ b/debug.go @@ -4,15 +4,9 @@ package ipfscluster func init() { l := "DEBUG" - for _, f := range facilities { - SetFacilityLogLevel(f, l) - } + SetFacilityLogLevel("*", l) - //SetFacilityLogLevel("cluster", l) - //SetFacilityLogLevel("consensus", l) - //SetFacilityLogLevel("monitor", "INFO") - //SetFacilityLogLevel("raft", l) - //SetFacilityLogLevel("p2p-gorpc", l) - //SetFacilityLogLevel("swarm2", l) - //SetFacilityLogLevel("libp2p-raft", l) + // for f, _ := range LoggingFacilities { + // SetFacilityLogLevel(f, l) + // } } diff --git a/ipfs-cluster-service/main.go b/ipfs-cluster-service/main.go index 474f76ca..ec4c3983 100644 --- a/ipfs-cluster-service/main.go +++ b/ipfs-cluster-service/main.go @@ -186,7 +186,7 @@ func main() { cli.StringFlag{ Name: "loglevel, l", Value: "info", - Usage: "set the loglevel for cluster only [critical, error, warning, info, debug]", + Usage: "set the loglevel for cluster components only [critical, error, warning, info, debug]", }, cli.StringFlag{ Name: "alloc, a", @@ -396,7 +396,7 @@ the mth data folder (m currently defaults to 5) configPath = filepath.Join(absPath, DefaultConfigFile) - setupLogging(c.String("loglevel")) + setupLogLevel(c.String("loglevel")) if c.Bool("debug") { setupDebug() } @@ -498,24 +498,8 @@ func daemon(c *cli.Context) error { } } -var facilities = []string{ - "service", - "cluster", - "restapi", - "ipfshttp", - "mapstate", - "monitor", - "consensus", - "pintracker", - "ascendalloc", - "descendalloc", - "diskinfo", - "config", - "apitypes", -} - -func setupLogging(lvl string) { - for _, f := range facilities { +func setupLogLevel(lvl string) { + for f := range ipfscluster.LoggingFacilities { ipfscluster.SetFacilityLogLevel(f, lvl) } } @@ -542,15 +526,7 @@ func setupAllocation(name string, diskInfCfg *disk.Config, numpinInfCfg *numpin. } func setupDebug() { - l := "DEBUG" - for _, f := range facilities { - ipfscluster.SetFacilityLogLevel(f, l) - } - - ipfscluster.SetFacilityLogLevel("p2p-gorpc", l) - ipfscluster.SetFacilityLogLevel("raft", l) - //SetFacilityLogLevel("swarm2", l) - //SetFacilityLogLevel("libp2p-raft", l) + ipfscluster.SetFacilityLogLevel("*", "DEBUG") } func saveConfig(cfg *config.Manager, force bool) { diff --git a/logging.go b/logging.go index 1bd07448..1c88f49a 100644 --- a/logging.go +++ b/logging.go @@ -4,18 +4,30 @@ import logging "github.com/ipfs/go-log" var logger = logging.Logger("cluster") -var facilities = []string{ - "cluster", - "restapi", - "ipfshttp", - "monitor", - "mapstate", - "consensus", - "raft", - "pintracker", - "ascendalloc", - "diskinfo", - "apitypes", +// LoggingFacilities provides a list of logging identifiers +// used by cluster and their default logging level. +var LoggingFacilities = map[string]string{ + "cluster": "INFO", + "restapi": "INFO", + "ipfshttp": "INFO", + "monitor": "INFO", + "mapstate": "INFO", + "consensus": "INFO", + "pintracker": "INFO", + "ascendalloc": "INFO", + "diskinfo": "INFO", + "apitypes": "INFO", + "config": "INFO", +} + +// LoggingFacilitiesExtra provides logging identifiers +// used in ipfs-cluster dependencies, which may be useful +// for to display. Along with their default value. +var LoggingFacilitiesExtra = map[string]string{ + "p2p-gorpc": "CRITICAL", + "swarm2": "ERROR", + "libp2p-raft": "CRITICAL", + "raft": "ERROR", } // SetFacilityLogLevel sets the log level for a given module diff --git a/nodebug.go b/nodebug.go index 27a3d4f3..9d407f1e 100644 --- a/nodebug.go +++ b/nodebug.go @@ -2,14 +2,13 @@ package ipfscluster -// This is our default logs levels +// These are our default log levels func init() { - for _, f := range facilities { - SetFacilityLogLevel(f, "INFO") + for f, l := range LoggingFacilities { + SetFacilityLogLevel(f, l) } - SetFacilityLogLevel("raft", "ERROR") - SetFacilityLogLevel("p2p-gorpc", "ERROR") - //SetFacilityLogLevel("swarm2", l) - SetFacilityLogLevel("libp2p-raft", "CRITICAL") + for f, l := range LoggingFacilitiesExtra { + SetFacilityLogLevel(f, l) + } } diff --git a/silent.go b/silent.go index fd97c58b..d03e06d0 100644 --- a/silent.go +++ b/silent.go @@ -4,11 +4,5 @@ package ipfscluster func init() { l := "CRITICAL" - for _, f := range facilities { - SetFacilityLogLevel(f, l) - } - - SetFacilityLogLevel("p2p-gorpc", l) - SetFacilityLogLevel("swarm2", l) - SetFacilityLogLevel("libp2p-raft", l) + SetFacilityLogLevel("*", l) }