From 410b7becd6795d84d517ba7347ec08131058264f Mon Sep 17 00:00:00 2001 From: sairoutine Date: Sun, 9 Dec 2018 17:52:19 +0900 Subject: [PATCH] Change DefaultLogFormatter to a private method --- logger.go | 8 ++++---- logger_test.go | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/logger.go b/logger.go index be4870f0..a64af697 100644 --- a/logger.go +++ b/logger.go @@ -28,7 +28,7 @@ var ( // LoggerConfig defines the config for Logger middleware. type LoggerConfig struct { - // Optional. Default value is gin.DefaultLogFormatter + // Optional. Default value is gin.defaultLogFormatter Formatter LogFormatter // Output is a writer where logs are written. @@ -56,8 +56,8 @@ type LogFormatterParams struct { IsTerm bool } -// DefaultLogFormatter is the default log format function Logger middleware uses. -var DefaultLogFormatter = func(param LogFormatterParams) string { +// defaultLogFormatter is the default log format function Logger middleware uses. +var defaultLogFormatter = func(param LogFormatterParams) string { var statusColor, methodColor, resetColor string if param.IsTerm { statusColor = colorForStatus(param.StatusCode) @@ -123,7 +123,7 @@ func LoggerWithWriter(out io.Writer, notlogged ...string) HandlerFunc { func LoggerWithConfig(conf LoggerConfig) HandlerFunc { formatter := conf.Formatter if formatter == nil { - formatter = DefaultLogFormatter + formatter = defaultLogFormatter } out := conf.Output diff --git a/logger_test.go b/logger_test.go index cbe3e25d..909ddd39 100644 --- a/logger_test.go +++ b/logger_test.go @@ -251,9 +251,9 @@ func TestDefaultLogFormatter(t *testing.T) { IsTerm: true, } - assert.Equal(t, "[GIN] 2018/12/07 - 09:11:42 | 200 | 5s | 20.20.20.20 | GET /\n", DefaultLogFormatter(termFalseParam)) + assert.Equal(t, "[GIN] 2018/12/07 - 09:11:42 | 200 | 5s | 20.20.20.20 | GET /\n", defaultLogFormatter(termFalseParam)) - assert.Equal(t, "[GIN] 2018/12/07 - 09:11:42 |\x1b[97;42m 200 \x1b[0m| 5s | 20.20.20.20 |\x1b[97;44m GET \x1b[0m /\n", DefaultLogFormatter(termTrueParam)) + assert.Equal(t, "[GIN] 2018/12/07 - 09:11:42 |\x1b[97;42m 200 \x1b[0m| 5s | 20.20.20.20 |\x1b[97;44m GET \x1b[0m /\n", defaultLogFormatter(termTrueParam)) } func TestColorForMethod(t *testing.T) {