fix insert timezero 0001-01-01 (#2635)

This commit is contained in:
haoc7 2019-09-02 09:44:50 +08:00 committed by Jinzhu
parent 836fb2c19d
commit 2a3ab99a08
1 changed files with 5 additions and 1 deletions

View File

@ -49,7 +49,11 @@ var LogFormatter = func(values ...interface{}) (messages []interface{}) {
if indirectValue.IsValid() { if indirectValue.IsValid() {
value = indirectValue.Interface() value = indirectValue.Interface()
if t, ok := value.(time.Time); ok { if t, ok := value.(time.Time); ok {
formattedValues = append(formattedValues, fmt.Sprintf("'%v'", t.Format("2006-01-02 15:04:05"))) if t.IsZero() {
formattedValues = append(formattedValues, fmt.Sprintf("'%v'", "0000-00-00 00:00:00"))
} else {
formattedValues = append(formattedValues, fmt.Sprintf("'%v'", t.Format("2006-01-02 15:04:05")))
}
} else if b, ok := value.([]byte); ok { } else if b, ok := value.([]byte); ok {
if str := string(b); isPrintable(str) { if str := string(b); isPrintable(str) {
formattedValues = append(formattedValues, fmt.Sprintf("'%v'", str)) formattedValues = append(formattedValues, fmt.Sprintf("'%v'", str))