master
Charles Iliya Krempeaux 2021-02-04 19:59:22 -08:00
parent 7054b98d69
commit 73a72074c0
2 changed files with 15 additions and 9 deletions

View File

@ -17,7 +17,7 @@ func (receiver internalLogger) Prefix(newprefix ...string) Logger {
prefix := buffer.String() prefix := buffer.String()
var logger internalLogger = receiver var logger internalLogger = receiver
logger.prefix += prefix logger.prefix = prefix
return &logger return &logger
} }

View File

@ -101,14 +101,20 @@ func TestLoggerPrefix_inform(t *testing.T) {
log.Debug("hello DEBUG") log.Debug("hello DEBUG")
log.Trace("hello TRACE") log.Trace("hello TRACE")
const expected = "[PANIC] one: two: three: hello PANIC" + "\n" +
"RECOVER:hello PANIC" + "\n" + log = log.Prefix("four")
"[inform] one: two: three: hello INFORM" + "\n" + log.Highlight("new prefix FOUR")
"[HIGHLIGHT] one: two: three: hello HIGHLIGHT" + "\n" +
"[ERROR] one: two: three: hello ERROR" + "\n" +
"[warn] one: two: three: hello WARN" + "\n" + const expected = "[PANIC] one: two: three: hello PANIC" + "\n" +
"[debug] one: two: three: hello DEBUG" + "\n" + "RECOVER:hello PANIC" + "\n" +
"[trace] one: two: three: hello TRACE" + "\n" "[inform] one: two: three: hello INFORM" + "\n" +
"[HIGHLIGHT] one: two: three: hello HIGHLIGHT" + "\n" +
"[ERROR] one: two: three: hello ERROR" + "\n" +
"[warn] one: two: three: hello WARN" + "\n" +
"[debug] one: two: three: hello DEBUG" + "\n" +
"[trace] one: two: three: hello TRACE" + "\n" +
"[HIGHLIGHT] one: two: three: four: new prefix FOUR" + "\n"
if actual := buffer.String(); expected != actual { if actual := buffer.String(); expected != actual {
t.Error("The actual logs is not what was expected.") t.Error("The actual logs is not what was expected.")