From 73a72074c06e66fe62ad63274567e70e099f449b Mon Sep 17 00:00:00 2001 From: Charles Iliya Krempeaux Date: Thu, 4 Feb 2021 19:59:22 -0800 Subject: [PATCH] logger --- internal_logger_prefix.go | 2 +- internal_logger_prefix_test.go | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/internal_logger_prefix.go b/internal_logger_prefix.go index 3f0142b..c25c6f7 100644 --- a/internal_logger_prefix.go +++ b/internal_logger_prefix.go @@ -17,7 +17,7 @@ func (receiver internalLogger) Prefix(newprefix ...string) Logger { prefix := buffer.String() var logger internalLogger = receiver - logger.prefix += prefix + logger.prefix = prefix return &logger } diff --git a/internal_logger_prefix_test.go b/internal_logger_prefix_test.go index ec5eb80..44bc023 100644 --- a/internal_logger_prefix_test.go +++ b/internal_logger_prefix_test.go @@ -101,14 +101,20 @@ func TestLoggerPrefix_inform(t *testing.T) { log.Debug("hello DEBUG") log.Trace("hello TRACE") - const expected = "[PANIC] one: two: three: hello PANIC" + "\n" + - "RECOVER:hello PANIC" + "\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" + + log = log.Prefix("four") + log.Highlight("new prefix FOUR") + + + const expected = "[PANIC] one: two: three: hello PANIC" + "\n" + + "RECOVER:hello PANIC" + "\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 { t.Error("The actual logs is not what was expected.")