Skip to content

Commit 7d83de6

Browse files
committed
WIP: Use a fixed size buffer for more log messages
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.
1 parent 87d4daa commit 7d83de6

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

c/src/core/logger.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,16 @@ void pni_logger_log(pn_logger_t *logger, pn_log_subsystem_t subsystem, pn_log_le
260260
void pni_logger_vlogf(pn_logger_t *logger, pn_log_subsystem_t subsystem, pn_log_level_t severity, const char *fmt, va_list ap)
261261
{
262262
assert(logger);
263-
pn_string_vformat(logger->scratch, fmt, ap);
264-
pni_logger_log(logger, subsystem, severity, pn_string_get(logger->scratch));
263+
char buf[1024];
264+
pn_fixed_string_t output = pn_fixed_string(buf, sizeof(buf));
265+
pn_fixed_string_vaddf(&output, fmt, ap);
266+
if (output.position==output.size) {
267+
// Message overflow
268+
const char truncated[] = " ... (truncated)";
269+
output.position -= sizeof(truncated);
270+
pn_fixed_string_append(&output, pn_string_const(truncated, sizeof(truncated)));
271+
}
272+
pni_logger_log(logger, subsystem, severity, buf);
265273
}
266274

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

0 commit comments

Comments
 (0)