printEntry renders the entry given as argument into s.finalBuf. If s.redactableOutput is set, then s.finalBuf is to contain a RedactableBytes, with redaction markers. In that case, we must be careful to escape (or not) the entry depending on entry.redactable. If s.redactableOutput is unset, then w
(entry formatEntry)
| 244 | // redactability. In that case entry.redactable is not set |
| 245 | // anyway and we can pass contents through. |
| 246 | func (s *state) printEntry(entry formatEntry) { |
| 247 | if len(entry.head) > 0 { |
| 248 | if entry.head[0] != '\n' { |
| 249 | s.finalBuf.WriteByte(' ') |
| 250 | } |
| 251 | if len(entry.head) > 0 { |
| 252 | if !s.redactableOutput || entry.redactable { |
| 253 | // If we don't care about redaction, then we can pass the string |
| 254 | // through. |
| 255 | // |
| 256 | // If we do care about redaction, and entry.redactable is true, |
| 257 | // then entry.head is already a RedactableBytes. Then we can |
| 258 | // also pass it through. |
| 259 | s.finalBuf.Write(entry.head) |
| 260 | } else { |
| 261 | // We care about redaction, and the head is unsafe. Escape it |
| 262 | // and enclose the result within redaction markers. |
| 263 | s.finalBuf.Write([]byte(redact.EscapeBytes(entry.head))) |
| 264 | } |
| 265 | } |
| 266 | } |
| 267 | if len(entry.details) > 0 { |
| 268 | if len(entry.head) == 0 { |
| 269 | if entry.details[0] != '\n' { |
| 270 | s.finalBuf.WriteByte(' ') |
| 271 | } |
| 272 | } |
| 273 | if !s.redactableOutput || entry.redactable { |
| 274 | // If we don't care about redaction, then we can pass the string |
| 275 | // through. |
| 276 | // |
| 277 | // If we do care about redaction, and entry.redactable is true, |
| 278 | // then entry.details is already a RedactableBytes. Then we can |
| 279 | // also pass it through. |
| 280 | s.finalBuf.Write(entry.details) |
| 281 | } else { |
| 282 | // We care about redaction, and the details are unsafe. Escape |
| 283 | // them and enclose the result within redaction markers. |
| 284 | s.finalBuf.Write([]byte(redact.EscapeBytes(entry.details))) |
| 285 | } |
| 286 | } |
| 287 | if entry.stackTrace != nil { |
| 288 | s.finalBuf.WriteString("\n -- stack trace:") |
| 289 | s.finalBuf.WriteString(strings.ReplaceAll( |
| 290 | fmt.Sprintf("%+v", entry.stackTrace), |
| 291 | "\n", string(detailSep))) |
| 292 | if entry.elidedStackTrace { |
| 293 | fmt.Fprintf(&s.finalBuf, "%s[...repeated from below...]", detailSep) |
| 294 | } |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | // formatSingleLineOutput prints the details extracted via |
| 299 | // formatRecursive() through the chain of errors as if .Error() has |