format formats a log record and writes it to the buffer.
(r slog.Record, buf *buffer)
| 172 | |
| 173 | // format formats a log record and writes it to the buffer. |
| 174 | func (h *Handler) format(r slog.Record, buf *buffer) { |
| 175 | groups := h.groups |
| 176 | |
| 177 | // If there are no attributes in the record itself, |
| 178 | // remove empty groups from the end |
| 179 | if r.NumAttrs() == 0 { |
| 180 | for len(groups) > 0 && len(groups[len(groups)-1].attrs) == 0 { |
| 181 | groups = groups[:len(groups)-1] |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | // Format the log record according to the format specified in options |
| 186 | switch h.config.Format { |
| 187 | case FormatPretty: |
| 188 | newFormatterPretty(groups, buf).format(r) |
| 189 | case FormatJSON: |
| 190 | newFormatterJSON(groups, buf, false).format(r) |
| 191 | case FormatGCP: |
| 192 | newFormatterJSON(groups, buf, true).format(r) |
| 193 | default: |
| 194 | newFormatterStructured(groups, buf).format(r) |
| 195 | } |
| 196 | |
| 197 | // Add line break after each log entry |
| 198 | buf.append('\n') |
| 199 | } |
| 200 | |
| 201 | func (h *Handler) joinErrors(errs []error) error { |
| 202 | if len(errs) == 0 { |
no test coverage detected