Skip to content
Snippets Groups Projects
Commit e679f436 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

logger: cleanup

Change-Id: I58028cad9b28b694ed271ebd1e9ebad7cd72f9fa
parent 14221db3
No related branches found
No related tags found
No related merge requests found
...@@ -96,6 +96,11 @@ ...@@ -96,6 +96,11 @@
#define LOGFILE "jami" #define LOGFILE "jami"
namespace jami {
static constexpr auto ENDL = '\n';
#ifndef __GLIBC__
static const char* static const char*
check_error(int result, char* buffer) check_error(int result, char* buffer)
{ {
...@@ -116,9 +121,10 @@ check_error(char* result, char*) ...@@ -116,9 +121,10 @@ check_error(char* result, char*)
{ {
return result; return result;
} }
#endif
void void
strErr(void) strErr()
{ {
#ifdef __GLIBC__ #ifdef __GLIBC__
JAMI_ERR("%m"); JAMI_ERR("%m");
...@@ -128,10 +134,6 @@ strErr(void) ...@@ -128,10 +134,6 @@ strErr(void)
#endif #endif
} }
namespace jami {
static constexpr auto ENDL = '\n';
// extract the last component of a pathname (extract a filename from its dirname) // extract the last component of a pathname (extract a filename from its dirname)
static const char* static const char*
stripDirName(const char* path) stripDirName(const char* path)
...@@ -183,7 +185,7 @@ formatPrintfArgs(const char* format, va_list ap) ...@@ -183,7 +185,7 @@ formatPrintfArgs(const char* format, va_list ap)
int size = vsnprintf(ret.data(), ret.size(), format, ap); int size = vsnprintf(ret.data(), ret.size(), format, ap);
/* Not enough space? Well try again. */ /* Not enough space? Well try again. */
if (size >= ret.size()) { if ((size_t)size >= ret.size()) {
ret.resize(size + 1); ret.resize(size + 1);
vsnprintf((char*) ret.data(), ret.size(), format, cp); vsnprintf((char*) ret.data(), ret.size(), format, cp);
} }
...@@ -200,17 +202,17 @@ struct Logger::Msg ...@@ -200,17 +202,17 @@ struct Logger::Msg
Msg() = delete; Msg() = delete;
Msg(int level, const char* file, int line, bool linefeed, std::string&& message) 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) , level_(level)
, linefeed_(linefeed) , linefeed_(linefeed)
, payload_(std::move(message))
{} {}
Msg(int level, const char* file, int line, bool linefeed, const char* fmt, va_list ap) 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) , level_(level)
, linefeed_(linefeed) , linefeed_(linefeed)
, payload_(formatPrintfArgs(fmt, ap))
{} {}
Msg(Msg&& other) Msg(Msg&& other)
...@@ -394,7 +396,7 @@ public: ...@@ -394,7 +396,7 @@ public:
#ifdef __ANDROID__ #ifdef __ANDROID__
__android_log_print(msg.level_, APP_NAME, "%s%s", msg.header_.c_str(), msg.payload_.c_str()); __android_log_print(msg.level_, APP_NAME, "%s%s", msg.header_.c_str(), msg.payload_.c_str());
#else #else
::syslog(msg.level_, "%s", msg.payload_.c_str()); ::syslog(msg.level_, "%.*s", (int)msg.payload_.size(), msg.payload_.data());
#endif #endif
} }
}; };
......
...@@ -35,19 +35,6 @@ ...@@ -35,19 +35,6 @@
#include <string> #include <string>
#include "string_utils.h" // to_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__ #ifdef __ANDROID__
#include <android/log.h> #include <android/log.h>
...@@ -80,6 +67,11 @@ void strErr(); ...@@ -80,6 +67,11 @@ void strErr();
namespace jami { 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. /// Level-driven logging class that support printf and C++ stream logging fashions.
/// ///
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment