2021-01-20 03:50:39 +03:00
|
|
|
package revid
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-05-27 09:12:52 +03:00
|
|
|
"bitbucket.org/ausocean/utils/logging"
|
2021-01-20 03:50:39 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// testLogger will allow logging to be done by the testing pkg.
|
|
|
|
type testLogger testing.T
|
|
|
|
|
2022-05-27 09:12:52 +03:00
|
|
|
func (tl *testLogger) Debug(msg string, args ...interface{}) { tl.Log(logging.Debug, msg, args...) }
|
|
|
|
func (tl *testLogger) Info(msg string, args ...interface{}) { tl.Log(logging.Info, msg, args...) }
|
|
|
|
func (tl *testLogger) Warning(msg string, args ...interface{}) { tl.Log(logging.Warning, msg, args...) }
|
|
|
|
func (tl *testLogger) Error(msg string, args ...interface{}) { tl.Log(logging.Error, msg, args...) }
|
|
|
|
func (tl *testLogger) Fatal(msg string, args ...interface{}) { tl.Log(logging.Fatal, msg, args...) }
|
2021-01-20 03:50:39 +03:00
|
|
|
func (tl *testLogger) SetLevel(lvl int8) {}
|
|
|
|
func (dl *testLogger) Log(lvl int8, msg string, args ...interface{}) {
|
|
|
|
var l string
|
|
|
|
switch lvl {
|
2022-05-27 09:12:52 +03:00
|
|
|
case logging.Warning:
|
2021-01-20 03:50:39 +03:00
|
|
|
l = "warning"
|
2022-05-27 09:12:52 +03:00
|
|
|
case logging.Debug:
|
2021-01-20 03:50:39 +03:00
|
|
|
l = "debug"
|
2022-05-27 09:12:52 +03:00
|
|
|
case logging.Info:
|
2021-01-20 03:50:39 +03:00
|
|
|
l = "info"
|
2022-05-27 09:12:52 +03:00
|
|
|
case logging.Error:
|
2021-01-20 03:50:39 +03:00
|
|
|
l = "error"
|
2022-05-27 09:12:52 +03:00
|
|
|
case logging.Fatal:
|
2021-01-20 03:50:39 +03:00
|
|
|
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 += " )"
|
|
|
|
|
2022-05-27 09:12:52 +03:00
|
|
|
if lvl == logging.Fatal {
|
2021-01-20 03:50:39 +03:00
|
|
|
dl.Fatalf(msg+"\n", args...)
|
|
|
|
}
|
|
|
|
|
|
|
|
dl.Logf(msg+"\n", args...)
|
|
|
|
}
|