MCPcopy Create free account
hub / github.com/apache/trafficserver / write_ascii_logbuffer

Method write_ascii_logbuffer

src/proxy/logging/LogFile.cc:505–567  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

503 -------------------------------------------------------------------------*/
504
505int
506LogFile::write_ascii_logbuffer(LogBufferHeader *buffer_header, int fd, const char *path, const char *alt_format)
507{
508 ink_assert(buffer_header != nullptr);
509 ink_assert(fd >= 0);
510
511 char fmt_buf[LOG_MAX_FORMATTED_BUFFER];
512 char fmt_line[LOG_MAX_FORMATTED_LINE];
513 LogBufferIterator iter(buffer_header);
514 LogEntryHeader *entry_header;
515 int fmt_buf_bytes = 0;
516 int fmt_line_bytes = 0;
517 int bytes = 0;
518
519 LogFormatType format_type;
520 char *fieldlist_str;
521 char *printf_str;
522
523 switch (buffer_header->version) {
524 case LOG_SEGMENT_VERSION:
525 format_type = static_cast<LogFormatType>(buffer_header->format_type);
526
527 fieldlist_str = buffer_header->fmt_fieldlist();
528 printf_str = buffer_header->fmt_printf();
529 break;
530
531 default:
532 Note("Invalid LogBuffer version %d in write_ascii_logbuffer; "
533 "current version is %d",
534 buffer_header->version, LOG_SEGMENT_VERSION);
535 return 0;
536 }
537
538 while ((entry_header = iter.next())) {
539 fmt_line_bytes = LogBuffer::to_ascii(entry_header, format_type, &fmt_line[0], LOG_MAX_FORMATTED_LINE, fieldlist_str, printf_str,
540 buffer_header->version, alt_format);
541 ink_assert(fmt_line_bytes > 0);
542
543 if (fmt_line_bytes > 0) {
544 if ((fmt_line_bytes + fmt_buf_bytes) >= LOG_MAX_FORMATTED_BUFFER) {
545 if (!Log::config->logging_space_exhausted) {
546 bytes += writeln(fmt_buf, fmt_buf_bytes, fd, path);
547 }
548 fmt_buf_bytes = 0;
549 }
550 ink_assert(fmt_buf_bytes < LOG_MAX_FORMATTED_BUFFER);
551 ink_assert(fmt_line_bytes < LOG_MAX_FORMATTED_BUFFER - fmt_buf_bytes);
552 memcpy(&fmt_buf[fmt_buf_bytes], fmt_line, fmt_line_bytes);
553 fmt_buf_bytes += fmt_line_bytes;
554 ink_assert(fmt_buf_bytes < LOG_MAX_FORMATTED_BUFFER);
555 fmt_buf[fmt_buf_bytes] = '\n'; // keep entries separate
556 fmt_buf_bytes += 1;
557 }
558 }
559 if (fmt_buf_bytes > 0) {
560 if (!Log::config->logging_space_exhausted) {
561 ink_assert(fmt_buf_bytes < LOG_MAX_FORMATTED_BUFFER);
562 bytes += writeln(fmt_buf, fmt_buf_bytes, fd, path);

Callers

nothing calls this directly

Calls 4

fmt_fieldlistMethod · 0.80
fmt_printfMethod · 0.80
memcpyFunction · 0.50
nextMethod · 0.45

Tested by

no test coverage detected