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 @@
#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
}
};
......
......@@ -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.
///
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment