Commit ffe2bdce authored by Juan Batiz-Benet's avatar Juan Batiz-Benet

init SetupLoggers

this is useful so that loggers are all setup during tests
parent 8e9b10f9
......@@ -80,7 +80,7 @@ func main() {
u.Debug = false
// setup logging
u.SetupLogging()
// u.SetupLogging() done in an init() block now.
// if debugging, setup profiling.
if u.Debug {
......
......@@ -17,8 +17,12 @@ import (
logging "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/op/go-logging"
)
func init() {
SetupLogging()
}
// LogFormat is the format used for our logger.
var LogFormat = "%{color}%{time:01-02 15:04:05.9999} %{shortfile} %{level}: %{color:reset}%{message}"
var LogFormat = "%{color}%{time:2006-01-02 15:04:05.999999} %{shortfile} %{level}: %{color:reset}%{message}"
// Debug is a global flag for debugging.
var Debug bool
......@@ -122,12 +126,14 @@ func DOut(format string, a ...interface{}) {
}
}
var loggers = []string{}
var loggers = map[string]*logging.Logger{}
// SetupLogging will initialize the logger backend and set the flags.
func SetupLogging() {
backend := logging.NewLogBackend(os.Stderr, "", 0)
logging.SetBackend(backend)
logging.SetFormatter(logging.MustStringFormatter(LogFormat))
/*
if Debug {
logging.SetLevel(logging.DEBUG, "")
......@@ -135,10 +141,10 @@ func SetupLogging() {
logging.SetLevel(logging.ERROR, "")
}
*/
logging.SetFormatter(logging.MustStringFormatter(LogFormat))
for _, n := range loggers {
for n, log := range loggers {
logging.SetLevel(logging.ERROR, n)
log.Error("setting logger: %s to %v\n", n, logging.ERROR)
}
}
......@@ -146,7 +152,7 @@ func SetupLogging() {
func Logger(name string) *logging.Logger {
log := logging.MustGetLogger(name)
// logging.SetLevel(lvl, name) // can't set level here.
loggers = append(loggers, name)
loggers[name] = log
return log
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment