@cryptotaxi247 / kubo / commits / 0631a3949

cleaned up SetupLogging()

Henry committed Oct 15, 2014 at 14:23 UTC 0631a39492aa5bca805816739eb6571626b701c5
2 files changed +10 -15
cmd/ipfs/ipfs.go
+1 -4
@@ -86,10 +86,7 @@ func ipfsCmd(c *commander.Command, args []string) error {
86 }
87
88 func main() {
89 - u.Debug = false
90 -
91 - // setup logging
92 - // u.SetupLogging() done in an init() block now.
89 + u.Debug = u.GetenvBool("IPFS_DEBUG")
90
91 // if debugging, setup profiling.
92 if u.Debug {
util/log.go
+9 -11
@@ -30,25 +30,23 @@ func SetupLogging() {
30 logging.SetBackend(backend)
31 logging.SetFormatter(logging.MustStringFormatter(LogFormat))
32
33 - // always print critical and error?
34 - SetAllLoggers(logging.CRITICAL)
35 - SetAllLoggers(logging.ERROR)
33 + lvl := logging.ERROR
34
35 if logenv := os.Getenv("IPFS_LOGGING"); logenv != "" {
38 - lvl, err := logging.LogLevel(logenv)
36 + var err error
37 + lvl, err = logging.LogLevel(logenv)
38 if err != nil {
40 - log.Error("logging.LogLevel() Error: %q\n", err)
41 - } else {
42 - SetAllLoggers(lvl)
39 + log.Error("logging.LogLevel() Error: %q", err)
40 + lvl = logging.ERROR // reset to ERROR, could be undefined now(?)
41 }
42 }
43
46 - if GetenvBool("IPFS_DEBUG") {
47 - log.Info("enabling debug printing")
48 - Debug = true
49 - SetAllLoggers(logging.DEBUG)
44 + if Debug {
45 + lvl = logging.DEBUG
46 }
47
48 + SetAllLoggers(lvl)
49 +
50 }
51
52 // SetAllLoggers changes the logging.Level of all loggers to lvl