fix: data race const readings
This commit is contained in:
parent
64ff1d551c
commit
e2ed6ffb4c
29
logger.go
29
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 (
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user