From 7054b98d69eb42786c8decbda21c2b87c841610b Mon Sep 17 00:00:00 2001 From: Charles Iliya Krempeaux Date: Thu, 4 Feb 2021 19:54:35 -0800 Subject: [PATCH] logger --- internal_logger_debug.go | 1 + internal_logger_error.go | 1 + internal_logger_fatal.go | 1 + internal_logger_highlight.go | 1 + internal_logger_inform.go | 1 + internal_logger_panic.go | 1 + internal_logger_prefix_test.go | 14 +++++++------- internal_logger_trace.go | 1 + internal_logger_warn.go | 1 + 9 files changed, 15 insertions(+), 7 deletions(-) diff --git a/internal_logger_debug.go b/internal_logger_debug.go index c1f9e0c..aeff5cb 100644 --- a/internal_logger_debug.go +++ b/internal_logger_debug.go @@ -45,6 +45,7 @@ func (receiver internalLogger) Debugf(format string, a ...interface{}) { buffer.WriteString("[debug] ") } + buffer.WriteString(receiver.prefix) buffer.WriteString(format) switch receiver.style { diff --git a/internal_logger_error.go b/internal_logger_error.go index 494348f..e74185c 100644 --- a/internal_logger_error.go +++ b/internal_logger_error.go @@ -40,6 +40,7 @@ func (receiver internalLogger) Errorf(format string, a ...interface{}) error { buffer.WriteString("[ERROR] ") } + buffer.WriteString(receiver.prefix) buffer.WriteString(format) switch receiver.style { diff --git a/internal_logger_fatal.go b/internal_logger_fatal.go index 6aff60a..8ce7c72 100644 --- a/internal_logger_fatal.go +++ b/internal_logger_fatal.go @@ -41,6 +41,7 @@ func (receiver internalLogger) Fatalf(format string, a ...interface{}) { buffer.WriteString("[PANIC] ") } + buffer.WriteString(receiver.prefix) buffer.WriteString(format) switch receiver.style { diff --git a/internal_logger_highlight.go b/internal_logger_highlight.go index 98de117..8ec41a0 100644 --- a/internal_logger_highlight.go +++ b/internal_logger_highlight.go @@ -45,6 +45,7 @@ func (receiver internalLogger) Highlightf(format string, a ...interface{}) { buffer.WriteString("[HIGHLIGHT] ") } + buffer.WriteString(receiver.prefix) buffer.WriteString(format) switch receiver.style { diff --git a/internal_logger_inform.go b/internal_logger_inform.go index 9c4e99a..da93024 100644 --- a/internal_logger_inform.go +++ b/internal_logger_inform.go @@ -45,6 +45,7 @@ func (receiver internalLogger) Informf(format string, a ...interface{}) { buffer.WriteString("[inform] ") } + buffer.WriteString(receiver.prefix) buffer.WriteString(format) switch receiver.style { diff --git a/internal_logger_panic.go b/internal_logger_panic.go index 570f195..812836a 100644 --- a/internal_logger_panic.go +++ b/internal_logger_panic.go @@ -40,6 +40,7 @@ func (receiver internalLogger) Panicf(format string, a ...interface{}) { buffer.WriteString("[PANIC] ") } + buffer.WriteString(receiver.prefix) buffer.WriteString(format) switch receiver.style { diff --git a/internal_logger_prefix_test.go b/internal_logger_prefix_test.go index 29193bc..ec5eb80 100644 --- a/internal_logger_prefix_test.go +++ b/internal_logger_prefix_test.go @@ -101,14 +101,14 @@ func TestLoggerPrefix_inform(t *testing.T) { log.Debug("hello DEBUG") log.Trace("hello TRACE") - const expected = "[PANIC] hello PANIC" + "\n" + + const expected = "[PANIC] one: two: three: hello PANIC" + "\n" + "RECOVER:hello PANIC" + "\n" + - "[inform] hello INFORM" + "\n" + - "[HIGHLIGHT] hello HIGHLIGHT" + "\n" + - "[ERROR] hello ERROR" + "\n" + - "[warn] hello WARN" + "\n" + - "[debug] hello DEBUG" + "\n" + - "[trace] 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" if actual := buffer.String(); expected != actual { t.Error("The actual logs is not what was expected.") diff --git a/internal_logger_trace.go b/internal_logger_trace.go index 8b3a8fb..929367d 100644 --- a/internal_logger_trace.go +++ b/internal_logger_trace.go @@ -45,6 +45,7 @@ func (receiver internalLogger) Tracef(format string, a ...interface{}) { buffer.WriteString("[trace] ") } + buffer.WriteString(receiver.prefix) buffer.WriteString(format) switch receiver.style { diff --git a/internal_logger_warn.go b/internal_logger_warn.go index 0f9b2e5..a4e109d 100644 --- a/internal_logger_warn.go +++ b/internal_logger_warn.go @@ -45,6 +45,7 @@ func (receiver internalLogger) Warnf(format string, a ...interface{}) { buffer.WriteString("[warn] ") } + buffer.WriteString(receiver.prefix) buffer.WriteString(format) switch receiver.style {