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 <code@hector.link>
This commit is contained in:
Hector Sanjuan 2018-01-11 18:09:10 +01:00
parent b8014927f6
commit 2a6f91cd35
5 changed files with 40 additions and 65 deletions

View File

@ -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)
// }
}

View File

@ -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) {

View File

@ -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

View File

@ -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)
}
}

View File

@ -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)
}