package revid import ( "testing" "bitbucket.org/ausocean/utils/logger" ) // testLogger will allow logging to be done by the testing pkg. type testLogger testing.T func (tl *testLogger) Debug(msg string, args ...interface{}) { tl.Log(logger.Debug, msg, args...) } func (tl *testLogger) Info(msg string, args ...interface{}) { tl.Log(logger.Info, msg, args...) } func (tl *testLogger) Warning(msg string, args ...interface{}) { tl.Log(logger.Warning, msg, args...) } func (tl *testLogger) Error(msg string, args ...interface{}) { tl.Log(logger.Error, msg, args...) } func (tl *testLogger) Fatal(msg string, args ...interface{}) { tl.Log(logger.Fatal, msg, args...) } func (tl *testLogger) SetLevel(lvl int8) {} func (dl *testLogger) Log(lvl int8, msg string, args ...interface{}) { var l string switch lvl { case logger.Warning: l = "warning" case logger.Debug: l = "debug" case logger.Info: l = "info" case logger.Error: l = "error" case logger.Fatal: l = "fatal" } msg = l + ": " + msg // Just use test.T.Log if no formatting required. if len(args) == 0 { ((*testing.T)(dl)).Log(msg) return } // Add braces with args inside to message. msg += " (" for i := 0; i < len(args); i += 2 { msg += " %v:\"%v\"" } msg += " )" if lvl == logger.Fatal { dl.Fatalf(msg+"\n", args...) } dl.Logf(msg+"\n", args...) }