log: move more instances of 'nil' to '<nil>'

This commit is contained in:
Jared Wasinger 2023-11-16 16:05:14 +08:00
parent 49ef852aeb
commit e89763002b
2 changed files with 6 additions and 6 deletions

View file

@ -126,12 +126,12 @@ func (h *TerminalHandler) logfmt(buf *bytes.Buffer, r slog.Record, color int) {
// formatValue formats a value for serialization
func FormatLogfmtValue(value interface{}, term bool) (result string) {
if value == nil {
return "nil"
return "<nil>"
}
defer func() {
if err := recover(); err != nil {
if v := reflect.ValueOf(value); v.Kind() == reflect.Ptr && v.IsNil() {
result = "nil"
result = "<nil>"
} else {
panic(err)
}
@ -149,7 +149,7 @@ func FormatLogfmtValue(value interface{}, term bool) (result string) {
// Big ints get consumed by the Stringer clause, so we need to handle
// them earlier on.
if v == nil {
return "nil"
return "<nil>"
}
return formatLogfmtBigInt(v)
@ -157,7 +157,7 @@ func FormatLogfmtValue(value interface{}, term bool) (result string) {
// Uint256s get consumed by the Stringer clause, so we need to handle
// them earlier on.
if v == nil {
return "nil"
return "<nil>"
}
return formatLogfmtUint256(v)
}

View file

@ -188,13 +188,13 @@ func builtinReplace(_ []string, attr slog.Attr) slog.Attr {
attr = slog.Any(attr.Key, v.Format(timeFormat))
case *big.Int:
if v == nil {
attr.Value = slog.StringValue("nil")
attr.Value = slog.StringValue("<nil>")
} else {
attr.Value = slog.StringValue(v.String())
}
case *uint256.Int:
if v == nil {
attr.Value = slog.StringValue("nil")
attr.Value = slog.StringValue("<nil>")
} else {
attr.Value = slog.StringValue(v.Dec())
}