Skip to content

Commit

Permalink
WIP: Use a fixed size buffer for more log messages
Browse files Browse the repository at this point in the history
The log messages that still use a pn_string_t either use that type
because of internal APIs or because they actually have a good case for
using a potentially unlimited amount of output.
  • Loading branch information
astitcher committed Dec 16, 2021
1 parent 87d4daa commit 7d83de6
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions c/src/core/logger.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,16 @@ void pni_logger_log(pn_logger_t *logger, pn_log_subsystem_t subsystem, pn_log_le
void pni_logger_vlogf(pn_logger_t *logger, pn_log_subsystem_t subsystem, pn_log_level_t severity, const char *fmt, va_list ap)
{
assert(logger);
pn_string_vformat(logger->scratch, fmt, ap);
pni_logger_log(logger, subsystem, severity, pn_string_get(logger->scratch));
char buf[1024];
pn_fixed_string_t output = pn_fixed_string(buf, sizeof(buf));
pn_fixed_string_vaddf(&output, fmt, ap);
if (output.position==output.size) {
// Message overflow
const char truncated[] = " ... (truncated)";
output.position -= sizeof(truncated);
pn_fixed_string_append(&output, pn_string_const(truncated, sizeof(truncated)));
}
pni_logger_log(logger, subsystem, severity, buf);
}

void pn_logger_logf(pn_logger_t *logger, pn_log_subsystem_t subsystem, pn_log_level_t severity, const char *fmt, ...)
Expand Down

0 comments on commit 7d83de6

Please sign in to comment.