@cryptotaxi247 / kubo / commits / ffe2bdcee

init SetupLoggers

this is useful so that loggers are all setup during tests

Juan Batiz-Benet committed Oct 8, 2014 at 02:50 UTC ffe2bdceef3a56d365b528e490a18f9f1b710bf3
2 files changed +12 -6
cmd/ipfs/ipfs.go
+1 -1
@@ -80,7 +80,7 @@ func main() {
80 u.Debug = false
81
82 // setup logging
83 - u.SetupLogging()
83 + // u.SetupLogging() done in an init() block now.
84
85 // if debugging, setup profiling.
86 if u.Debug {
util/util.go
+11 -5
@@ -17,8 +17,12 @@ import (
17 logging "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/op/go-logging"
18 )
19
20 +func init() {
21 + SetupLogging()
22 +}
23 +
24 // LogFormat is the format used for our logger.
21 -var LogFormat = "%{color}%{time:01-02 15:04:05.9999} %{shortfile} %{level}: %{color:reset}%{message}"
25 +var LogFormat = "%{color}%{time:2006-01-02 15:04:05.999999} %{shortfile} %{level}: %{color:reset}%{message}"
26
27 // Debug is a global flag for debugging.
28 var Debug bool
@@ -122,12 +126,14 @@ func DOut(format string, a ...interface{}) {
126 }
127 }
128
125 -var loggers = []string{}
129 +var loggers = map[string]*logging.Logger{}
130
131 // SetupLogging will initialize the logger backend and set the flags.
132 func SetupLogging() {
133 backend := logging.NewLogBackend(os.Stderr, "", 0)
134 logging.SetBackend(backend)
135 + logging.SetFormatter(logging.MustStringFormatter(LogFormat))
136 +
137 /*
138 if Debug {
139 logging.SetLevel(logging.DEBUG, "")
@@ -135,10 +141,10 @@ func SetupLogging() {
141 logging.SetLevel(logging.ERROR, "")
142 }
143 */
138 - logging.SetFormatter(logging.MustStringFormatter(LogFormat))
144
140 - for _, n := range loggers {
145 + for n, log := range loggers {
146 logging.SetLevel(logging.ERROR, n)
147 + log.Error("setting logger: %s to %v\n", n, logging.ERROR)
148 }
149 }
150
@@ -146,7 +152,7 @@ func SetupLogging() {
152 func Logger(name string) *logging.Logger {
153 log := logging.MustGetLogger(name)
154 // logging.SetLevel(lvl, name) // can't set level here.
149 - loggers = append(loggers, name)
155 + loggers[name] = log
156 return log
157 }
158