mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
log: fix terminal format
This commit is contained in:
parent
de3c7fbc1b
commit
c9dc6d7658
1 changed files with 14 additions and 6 deletions
|
|
@ -124,10 +124,19 @@ func (h *TerminalHandler) logfmt(buf *bytes.Buffer, r slog.Record, color int) {
|
|||
}
|
||||
|
||||
// formatValue formats a value for serialization
|
||||
func FormatLogfmtValue(value interface{}, term bool) string {
|
||||
func FormatLogfmtValue(value interface{}, term bool) (result string) {
|
||||
if value == nil {
|
||||
return "nil"
|
||||
}
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
if v := reflect.ValueOf(value); v.Kind() == reflect.Ptr && v.IsNil() {
|
||||
result = "nil"
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
switch v := value.(type) {
|
||||
case time.Time:
|
||||
|
|
@ -151,11 +160,6 @@ func FormatLogfmtValue(value interface{}, term bool) string {
|
|||
return "nil"
|
||||
}
|
||||
return formatLogfmtUint256(v)
|
||||
case error:
|
||||
return v.Error()
|
||||
|
||||
case fmt.Stringer:
|
||||
return v.String()
|
||||
}
|
||||
if term {
|
||||
if s, ok := value.(TerminalStringer); ok {
|
||||
|
|
@ -164,6 +168,10 @@ func FormatLogfmtValue(value interface{}, term bool) string {
|
|||
}
|
||||
}
|
||||
switch v := value.(type) {
|
||||
case error:
|
||||
return v.Error()
|
||||
case fmt.Stringer:
|
||||
return v.String()
|
||||
case bool:
|
||||
return strconv.FormatBool(v)
|
||||
case float32:
|
||||
|
|
|
|||
Loading…
Reference in a new issue