Skip to content

Commit

Permalink
Support error in slog.Any, discard the data attribute when no child
Browse files Browse the repository at this point in the history
  • Loading branch information
SpeedxPz committed Oct 4, 2022
1 parent 0d6cc21 commit d4cce36
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions slog.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,22 @@ func (s SukiLogger) appLogBuilder(args ...interface{}) []zap.Field {
appData := make(map[string]interface{})

for i, _ := range args {
if val, ok := args[i].(TraceInfo); ok {
data["tracing"] = val
} else if val, ok := args[i].(LogField); ok {
appData[val.Key] = val.Value
if field, ok := args[i].(TraceInfo); ok {
data["tracing"] = field
} else if field, ok := args[i].(LogField); ok {
if val, ok := field.Value.(error); ok {
appData[field.Key] = val.Error()
} else {
appData[field.Key] = field.Value
}

}
}
data[appKey] = appData

if len(appData) > 0 {
data[appKey] = appData
}

dataField := zap.Any("data", data)

return []zap.Field{
Expand Down

0 comments on commit d4cce36

Please sign in to comment.