Commit 6c91c7ab authored by Tristan Matthews's avatar Tristan Matthews

logger: fix logStr for non-glibc, add optional message argument

Change-Id: I3b503510bd30b80b15222610262e29d6928f951b
parent ba5552e3
......@@ -86,26 +86,33 @@ bool getDebugMode()
return debugMode;
}
void strErr()
void strErr(const char *msg)
{
#ifdef __GLIBC__
ERROR("%m");
if (strlen(msg))
ERROR("%s: %m", msg);
else
ERROR("%m");
#else
char buf[1000];
const char *msg;
const char *errstr;
switch (strerror_r(error, buf, sizeof(buf))) {
switch (strerror_r(errno, buf, sizeof(buf))) {
case 0:
msg = buf;
errstr = buf;
break;
case ERANGE: /* should never happen */
msg = "unknown (too big to display)";
errstr = "unknown (too big to display)";
break;
default:
msg = "unknown (invalid error number)";
errstr = "unknown (invalid error number)";
break;
}
ERROR("%s", msg);
if (strlen(msg))
ERROR("%s: %s", msg, errstr);
else
ERROR("%s", errstr);
#endif
}
}
......@@ -39,13 +39,18 @@
#include <syslog.h>
#endif
#include <cstring>
namespace Logger {
void log(const int, const char*, ...);
void setConsoleLog(bool);
void setDebugMode(bool);
bool getDebugMode();
void strErr();
/**
* Thread-safe function to print the stringified contents of errno appended to a
* user defined message */
void strErr(const char *message = "");
};
#define LOG_FORMAT(M, ...) "%s:%d:0x%x: " M, FILE_NAME, __LINE__, (unsigned long) pthread_self() & 0xffff, ##__VA_ARGS__
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment