mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
log: remove formatShared.
This commit is contained in:
parent
9f616add5f
commit
de3c7fbc1b
1 changed files with 5 additions and 27 deletions
|
|
@ -123,32 +123,6 @@ func (h *TerminalHandler) logfmt(buf *bytes.Buffer, r slog.Record, color int) {
|
||||||
buf.WriteByte('\n')
|
buf.WriteByte('\n')
|
||||||
}
|
}
|
||||||
|
|
||||||
func formatShared(value interface{}) (result interface{}) {
|
|
||||||
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:
|
|
||||||
return v.Format(timeFormat)
|
|
||||||
|
|
||||||
case error:
|
|
||||||
return v.Error()
|
|
||||||
|
|
||||||
case fmt.Stringer:
|
|
||||||
return v.String()
|
|
||||||
|
|
||||||
default:
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// formatValue formats a value for serialization
|
// formatValue formats a value for serialization
|
||||||
func FormatLogfmtValue(value interface{}, term bool) string {
|
func FormatLogfmtValue(value interface{}, term bool) string {
|
||||||
if value == nil {
|
if value == nil {
|
||||||
|
|
@ -177,6 +151,11 @@ func FormatLogfmtValue(value interface{}, term bool) string {
|
||||||
return "nil"
|
return "nil"
|
||||||
}
|
}
|
||||||
return formatLogfmtUint256(v)
|
return formatLogfmtUint256(v)
|
||||||
|
case error:
|
||||||
|
return v.Error()
|
||||||
|
|
||||||
|
case fmt.Stringer:
|
||||||
|
return v.String()
|
||||||
}
|
}
|
||||||
if term {
|
if term {
|
||||||
if s, ok := value.(TerminalStringer); ok {
|
if s, ok := value.(TerminalStringer); ok {
|
||||||
|
|
@ -184,7 +163,6 @@ func FormatLogfmtValue(value interface{}, term bool) string {
|
||||||
return escapeString(s.TerminalString())
|
return escapeString(s.TerminalString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
value = formatShared(value)
|
|
||||||
switch v := value.(type) {
|
switch v := value.(type) {
|
||||||
case bool:
|
case bool:
|
||||||
return strconv.FormatBool(v)
|
return strconv.FormatBool(v)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue