appendJSONMarshal appends a JSON marshaled value to the buffer.
(val any)
| 196 | |
| 197 | // appendJSONMarshal appends a JSON marshaled value to the buffer. |
| 198 | func (s *formatterJSON) appendJSONMarshal(val any) { |
| 199 | if err, ok := val.(error); ok && err != nil { |
| 200 | s.appendString(err.Error()) |
| 201 | return |
| 202 | } |
| 203 | |
| 204 | buf := newBuffer() |
| 205 | defer func() { |
| 206 | buf.free() |
| 207 | }() |
| 208 | |
| 209 | enc := json.NewEncoder(buf) |
| 210 | enc.SetEscapeHTML(false) |
| 211 | |
| 212 | if err := enc.Encode(val); err != nil { |
| 213 | // This should be a very unlikely situation, but just in case... |
| 214 | s.buf.appendStringRaw(`"<json marshal error>"`) |
| 215 | return |
| 216 | } |
| 217 | |
| 218 | buf.removeNewline() |
| 219 | s.buf.append(*buf...) |
| 220 | } |
| 221 | |
| 222 | // appendGroup appends a group of attributes to the buffer. |
| 223 | func (s *formatterJSON) appendGroup(name string, attrs []slog.Attr) { |
no test coverage detected