| 384 | } // namespace |
| 385 | |
| 386 | size_t |
| 387 | DebugInterface::generate_format_string(swoc::LocalBufferWriter<1024> &format_writer, const char *debug_tag, DiagsLevel diags_level, |
| 388 | const SourceLocation *loc, DiagsShowLocation show_location, const char *format_string) |
| 389 | { |
| 390 | // Save room for optional newline and terminating NUL bytes. |
| 391 | format_writer.restrict(2); |
| 392 | |
| 393 | format_writer.print("[{}] ", DiagTimestamp{}); |
| 394 | auto timestamp_offset = format_writer.size(); |
| 395 | |
| 396 | format_writer.print("{} {}: ", DiagThreadname{}, level_name(diags_level)); |
| 397 | |
| 398 | if (location(loc, show_location, diags_level)) { |
| 399 | format_writer.print("<{}> ", *loc); |
| 400 | } |
| 401 | |
| 402 | if (debug_tag) { |
| 403 | format_writer.print("({}) ", debug_tag); |
| 404 | } |
| 405 | |
| 406 | format_writer.print("{}", format_string); |
| 407 | |
| 408 | format_writer.restore(2); // restore the space for required termination. |
| 409 | if (format_writer.view().back() != '\n') { // safe because always some chars in the buffer. |
| 410 | format_writer.write('\n'); |
| 411 | } |
| 412 | format_writer.write('\0'); |
| 413 | |
| 414 | return timestamp_offset; |
| 415 | } |