From 6dc132df27858f4b8801417bc501a8d68038cb46 Mon Sep 17 00:00:00 2001 From: Peter Keresztes Schmidt Date: Tue, 2 Feb 2021 16:29:55 +0100 Subject: [PATCH] zmc: Use fmt to construct the log ID --- src/CMakeLists.txt | 1 + src/zmc.cpp | 17 +++++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 94eea7e67..f4167dd8e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -92,6 +92,7 @@ target_link_libraries(zmc PRIVATE zm-core-interface zm + fmt::fmt ${ZM_EXTRA_LIBS} ${ZM_BIN_LIBS} ${CMAKE_DL_LIBS}) diff --git a/src/zmc.cpp b/src/zmc.cpp index b197e5019..578841729 100644 --- a/src/zmc.cpp +++ b/src/zmc.cpp @@ -63,6 +63,7 @@ possible, this should run at more or less constant speed. #include "zm_signal.h" #include "zm_time.h" #include "zm_utils.h" +#include #include #include @@ -169,24 +170,24 @@ int main(int argc, char *argv[]) { exit(0); } - char log_id_string[32] = ""; + std::string logId; if ( device[0] ) { const char *slash_ptr = strrchr(device, '/'); - snprintf(log_id_string, sizeof(log_id_string), "zmc_d%s", slash_ptr?slash_ptr+1:device); + logId = fmt::format("zmc_d{}", slash_ptr ? slash_ptr + 1 : device); } else if ( host[0] ) { - snprintf(log_id_string, sizeof(log_id_string), "zmc_h%s", host); + logId = fmt::format("zmc_h{}", host); } else if ( file[0] ) { const char *slash_ptr = strrchr(file, '/'); - snprintf(log_id_string, sizeof(log_id_string), "zmc_f%s", slash_ptr?slash_ptr+1:file); + logId = fmt::format("zmc_f{}", slash_ptr ? slash_ptr + 1 : file); } else { - snprintf(log_id_string, sizeof(log_id_string), "zmc_m%d", monitor_id); + logId = fmt::format("zmc_m{}", monitor_id); } - logInit(log_id_string); + logInit(logId.c_str()); zmLoadStaticConfig(); zmDbConnect(); zmLoadDBConfig(); - logInit(log_id_string); + logInit(logId.c_str()); hwcaps_detect(); @@ -409,7 +410,7 @@ int main(int argc, char *argv[]) { monitor->Reload(); } logTerm(); - logInit(log_id_string); + logInit(logId.c_str()); zm_reload = false; } // end if zm_reload } // end while ! zm_terminate outer connection loop