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)}
|
defaultLogger = Logger{log.New(os.Stdout, "\r\n", 0)}
|
||||||
sqlRegexp = regexp.MustCompile(`\?`)
|
sqlRegexp = regexp.MustCompile(`\?`)
|
||||||
numericPlaceHolderRegexp = regexp.MustCompile(`\$\d+`)
|
numericPlaceHolderRegexp = regexp.MustCompile(`\$\d+`)
|
||||||
reset = ""
|
reset = RESET
|
||||||
cyan = ""
|
cyan = CYAN
|
||||||
magenta = ""
|
magenta = MAGENTA
|
||||||
red = ""
|
red = RED
|
||||||
redBold = ""
|
redBold = REDBOLD
|
||||||
yellow = ""
|
yellow = YELLOW
|
||||||
)
|
)
|
||||||
|
|
||||||
func isPrintable(s string) bool {
|
func isPrintable(s string) bool {
|
||||||
@ -54,6 +54,16 @@ func NoColor() bool {
|
|||||||
return os.Getenv("NO_COLOR") != ""
|
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
|
// LogFormatter is a default logger with timestamps, sql error handling, loglevel and NO_COLOR support
|
||||||
var LogFormatter = func(values ...interface{}) (messages []interface{}) {
|
var LogFormatter = func(values ...interface{}) (messages []interface{}) {
|
||||||
suppressColor := NoColor()
|
suppressColor := NoColor()
|
||||||
@ -66,13 +76,6 @@ var LogFormatter = func(values ...interface{}) (messages []interface{}) {
|
|||||||
yellow = ""
|
yellow = ""
|
||||||
redBold = ""
|
redBold = ""
|
||||||
magenta = ""
|
magenta = ""
|
||||||
} else {
|
|
||||||
red = RED
|
|
||||||
cyan = CYAN
|
|
||||||
reset = RESET
|
|
||||||
yellow = YELLOW
|
|
||||||
redBold = REDBOLD
|
|
||||||
magenta = MAGENTA
|
|
||||||
}
|
}
|
||||||
if len(values) > 1 {
|
if len(values) > 1 {
|
||||||
var (
|
var (
|
||||||
|
@ -15,7 +15,7 @@ func TestNoColor(t *testing.T) {
|
|||||||
l := gorm.Logger{log.New(os.Stdout, "\r\n", 0)}
|
l := gorm.Logger{log.New(os.Stdout, "\r\n", 0)}
|
||||||
l.Print("info", "[info] NO_COLOR log test")
|
l.Print("info", "[info] NO_COLOR log test")
|
||||||
os.Setenv("NO_COLOR", "")
|
os.Setenv("NO_COLOR", "")
|
||||||
gorm.NoColor()
|
gorm.ResetColors()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSQLLog(t *testing.T) {
|
func TestSQLLog(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user