From 0631a39492aa5bca805816739eb6571626b701c5 Mon Sep 17 00:00:00 2001 From: Henry <cryptix@riseup.net> Date: Wed, 15 Oct 2014 14:23:54 +0200 Subject: [PATCH] cleaned up SetupLogging() --- cmd/ipfs/ipfs.go | 5 +---- util/log.go | 20 +++++++++----------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/cmd/ipfs/ipfs.go b/cmd/ipfs/ipfs.go index fe0594fcc..bc5922dd8 100644 --- a/cmd/ipfs/ipfs.go +++ b/cmd/ipfs/ipfs.go @@ -86,10 +86,7 @@ func ipfsCmd(c *commander.Command, args []string) error { } func main() { - u.Debug = false - - // setup logging - // u.SetupLogging() done in an init() block now. + u.Debug = u.GetenvBool("IPFS_DEBUG") // if debugging, setup profiling. if u.Debug { diff --git a/util/log.go b/util/log.go index fd4f4ad69..b10c9e705 100644 --- a/util/log.go +++ b/util/log.go @@ -30,25 +30,23 @@ func SetupLogging() { logging.SetBackend(backend) logging.SetFormatter(logging.MustStringFormatter(LogFormat)) - // always print critical and error? - SetAllLoggers(logging.CRITICAL) - SetAllLoggers(logging.ERROR) + lvl := logging.ERROR if logenv := os.Getenv("IPFS_LOGGING"); logenv != "" { - lvl, err := logging.LogLevel(logenv) + var err error + lvl, err = logging.LogLevel(logenv) if err != nil { - log.Error("logging.LogLevel() Error: %q\n", err) - } else { - SetAllLoggers(lvl) + log.Error("logging.LogLevel() Error: %q", err) + lvl = logging.ERROR // reset to ERROR, could be undefined now(?) } } - if GetenvBool("IPFS_DEBUG") { - log.Info("enabling debug printing") - Debug = true - SetAllLoggers(logging.DEBUG) + if Debug { + lvl = logging.DEBUG } + SetAllLoggers(lvl) + } // SetAllLoggers changes the logging.Level of all loggers to lvl -- GitLab