Catch exceptions thrown on invalid format strings in the log backend and print an error message to signal the issue.

master
faluco 3 years ago committed by faluco
parent 07019a5bd6
commit 8cde3f20e7

@ -28,7 +28,11 @@ void json_formatter::format(detail::log_entry_metadata&& metadata, fmt::memory_b
if (metadata.fmtstring) {
if (metadata.store) {
fmt::basic_format_args<fmt::basic_printf_context_t<char> > args(*metadata.store);
try {
fmt::vprintf(buffer, fmt::to_string_view(metadata.fmtstring), args);
} catch (...) {
fmt::print(stderr, "srsLog error - Invalid format string: \"{}\"\n", metadata.fmtstring);
}
fmt::format_to(buffer, fmt::to_string_view("\""));
} else {
fmt::format_to(buffer, "{}\"", metadata.fmtstring);
@ -58,7 +62,11 @@ void json_formatter::format_context_begin(const detail::log_entry_metadata& md,
if (md.store) {
fmt::format_to(buffer, " \"log_entry\": \"");
fmt::basic_format_args<fmt::basic_printf_context_t<char> > args(*md.store);
try {
fmt::vprintf(buffer, fmt::to_string_view(md.fmtstring), args);
} catch (...) {
fmt::print(stderr, "srsLog error - Invalid format string: \"{}\"\n", md.fmtstring);
}
fmt::format_to(buffer, "\",\n");
} else {
fmt::format_to(buffer, " \"log_entry\": \"{}\",\n", md.fmtstring);

@ -66,7 +66,11 @@ void text_formatter::format(detail::log_entry_metadata&& metadata, fmt::memory_b
if (metadata.fmtstring) {
if (metadata.store) {
fmt::basic_format_args<fmt::basic_printf_context_t<char> > args(*metadata.store);
try {
fmt::vprintf(buffer, fmt::to_string_view(metadata.fmtstring), args);
} catch (...) {
fmt::print(stderr, "srsLog error - Invalid format string: \"{}\"\n", metadata.fmtstring);
}
fmt::format_to(buffer, "\n");
} else {
fmt::format_to(buffer, "{}\n", metadata.fmtstring);
@ -106,7 +110,11 @@ void text_formatter::format_context_end(const detail::log_entry_metadata& md,
if (md.store) {
fmt::format_to(buffer, "]: ");
fmt::basic_format_args<fmt::basic_printf_context_t<char> > args(*md.store);
try {
fmt::vprintf(buffer, fmt::to_string_view(md.fmtstring), args);
} catch (...) {
fmt::print(stderr, "srsLog error - Invalid format string: \"{}\"\n", md.fmtstring);
}
fmt::format_to(buffer, "\n");
} else {
fmt::format_to(buffer, "]: {}\n", md.fmtstring);

Loading…
Cancel
Save