diff --git a/src/logger.cpp b/src/logger.cpp index 1d22d515ef701ade739697ff326e0f4b6bd0e882..d26a66a5554d78450ae87167725cf828874208db 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -96,6 +96,11 @@ #define LOGFILE "jami" +namespace jami { + +static constexpr auto ENDL = '\n'; + +#ifndef __GLIBC__ static const char* check_error(int result, char* buffer) { @@ -116,9 +121,10 @@ check_error(char* result, char*) { return result; } +#endif void -strErr(void) +strErr() { #ifdef __GLIBC__ JAMI_ERR("%m"); @@ -128,10 +134,6 @@ strErr(void) #endif } -namespace jami { - -static constexpr auto ENDL = '\n'; - // extract the last component of a pathname (extract a filename from its dirname) static const char* stripDirName(const char* path) @@ -183,7 +185,7 @@ formatPrintfArgs(const char* format, va_list ap) int size = vsnprintf(ret.data(), ret.size(), format, ap); /* Not enough space? Well try again. */ - if (size >= ret.size()) { + if ((size_t)size >= ret.size()) { ret.resize(size + 1); vsnprintf((char*) ret.data(), ret.size(), format, cp); } @@ -200,17 +202,17 @@ struct Logger::Msg Msg() = delete; Msg(int level, const char* file, int line, bool linefeed, std::string&& message) - : header_(contextHeader(file, line)) + : payload_(std::move(message)) + , header_(contextHeader(file, line)) , level_(level) , linefeed_(linefeed) - , payload_(std::move(message)) {} Msg(int level, const char* file, int line, bool linefeed, const char* fmt, va_list ap) - : header_(contextHeader(file, line)) + : payload_(formatPrintfArgs(fmt, ap)) + , header_(contextHeader(file, line)) , level_(level) , linefeed_(linefeed) - , payload_(formatPrintfArgs(fmt, ap)) {} Msg(Msg&& other) @@ -394,7 +396,7 @@ public: #ifdef __ANDROID__ __android_log_print(msg.level_, APP_NAME, "%s%s", msg.header_.c_str(), msg.payload_.c_str()); #else - ::syslog(msg.level_, "%s", msg.payload_.c_str()); + ::syslog(msg.level_, "%.*s", (int)msg.payload_.size(), msg.payload_.data()); #endif } }; diff --git a/src/logger.h b/src/logger.h index 087c8b5279c4ea5b0cf3a747396748b75f98cca9..290b1ab534de04d7a525d5168929c874948abd46 100644 --- a/src/logger.h +++ b/src/logger.h @@ -35,19 +35,6 @@ #include <string> #include "string_utils.h" // to_string -#ifdef __cplusplus -extern "C" { -#endif - -/** - * Thread-safe function to print the stringified contents of errno - */ -void strErr(); - -#ifdef __cplusplus -} -#endif - #ifdef __ANDROID__ #include <android/log.h> @@ -80,6 +67,11 @@ void strErr(); namespace jami { +/** + * Thread-safe function to print the stringified contents of errno + */ +void strErr(); + /// /// Level-driven logging class that support printf and C++ stream logging fashions. ///