Skip to content

Commit

Permalink
Refactor cbdb_log to use vfprintf
Browse files Browse the repository at this point in the history
Using vfprintf to avoid unnecessary buffer
  • Loading branch information
ruhuang2001 authored and my-ship-it committed Jul 29, 2024
1 parent d7b5762 commit a5d00de
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions src/fe_utils/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,28 +97,17 @@ cbdb_log(cbdb_log_level level, const char* file, int line, const char* format, .
snprintf(timestamp, MAX_TIMESTAMP_LENGTH, "%s.%06ld", date, (long) tv.tv_usec);

// record timestamp, file name, and line num
len = snprintf(NULL, 0, fmt, timestamp, s_level[level], file, line);
if (len > 0)
{
char buffer[1000];
snprintf(buffer, len + 1, fmt, timestamp, s_level[level], file, line);
buffer[len] = 0;
fprintf(log_file, "%s,", buffer);
}
fprintf(log_file, fmt, timestamp, s_level[level], file, line);
fprintf(log_file, ",");

// record log information
va_list arg_ptr;
va_start(arg_ptr, format);
len = vsnprintf(NULL, 0, format, arg_ptr);
len = vfprintf(log_file, format, arg_ptr);
va_end(arg_ptr);
if (len > 0)
{
char buffer[1000];
va_start(arg_ptr, format);
vsnprintf(buffer, len + 1, format, arg_ptr);
va_end(arg_ptr);
buffer[len] = 0;
fprintf(log_file, "%s\n", buffer);
fprintf(log_file, "\n");
}

cur_line_num ++;
Expand Down

0 comments on commit a5d00de

Please sign in to comment.