diff --git a/logger.go b/logger.go index f0a3220b..7471e707 100644 --- a/logger.go +++ b/logger.go @@ -31,12 +31,12 @@ var ( defaultLogger = Logger{log.New(os.Stdout, "\r\n", 0)} sqlRegexp = regexp.MustCompile(`\?`) numericPlaceHolderRegexp = regexp.MustCompile(`\$\d+`) - reset = "" - cyan = "" - magenta = "" - red = "" - redBold = "" - yellow = "" + reset = RESET + cyan = CYAN + magenta = MAGENTA + red = RED + redBold = REDBOLD + yellow = YELLOW ) func isPrintable(s string) bool { @@ -54,6 +54,16 @@ func NoColor() bool { return os.Getenv("NO_COLOR") != "" } +// ResetColors reads consts colors for test cases +func ResetColors() { + red = RED + cyan = CYAN + reset = RESET + yellow = YELLOW + redBold = REDBOLD + magenta = MAGENTA +} + // LogFormatter is a default logger with timestamps, sql error handling, loglevel and NO_COLOR support var LogFormatter = func(values ...interface{}) (messages []interface{}) { suppressColor := NoColor() @@ -66,13 +76,6 @@ var LogFormatter = func(values ...interface{}) (messages []interface{}) { yellow = "" redBold = "" magenta = "" - } else { - red = RED - cyan = CYAN - reset = RESET - yellow = YELLOW - redBold = REDBOLD - magenta = MAGENTA } if len(values) > 1 { var ( diff --git a/logger_test.go b/logger_test.go index ca7a8b41..b7a8c0f2 100644 --- a/logger_test.go +++ b/logger_test.go @@ -15,7 +15,7 @@ func TestNoColor(t *testing.T) { l := gorm.Logger{log.New(os.Stdout, "\r\n", 0)} l.Print("info", "[info] NO_COLOR log test") os.Setenv("NO_COLOR", "") - gorm.NoColor() + gorm.ResetColors() } func TestSQLLog(t *testing.T) {