Skip to content
Snippets Groups Projects
Commit dc84e63f authored by Rafaël Carré's avatar Rafaël Carré Committed by Tristan Matthews
Browse files

Logger::log() : simplify

Also use a bigger buffer and do not overflow it
parent ff313727
Branches
Tags
No related merge requests found
...@@ -41,15 +41,12 @@ bool debugMode = false; ...@@ -41,15 +41,12 @@ bool debugMode = false;
void log (const int level, const char* format, ...) void log (const int level, const char* format, ...)
{ {
using std::string;
if (!debugMode && level == LOG_DEBUG) if (!debugMode && level == LOG_DEBUG)
return; return;
va_list ap; va_list ap;
string prefix = "<> "; const char *prefix = "<> ";
char buffer[4096]; const char *color_prefix = "";
string message = "";
string color_prefix = "";
switch (level) { switch (level) {
case LOG_ERR: { case LOG_ERR: {
...@@ -74,19 +71,15 @@ void log (const int level, const char* format, ...) ...@@ -74,19 +71,15 @@ void log (const int level, const char* format, ...)
} }
} }
char buffer[8192];
va_start (ap, format); va_start (ap, format);
vsprintf (buffer, format, ap); vsnprintf (buffer, sizeof buffer, format, ap);
va_end (ap); va_end (ap);
message = buffer; if (consoleLog)
message = prefix + message; fprintf(stderr, "%s%s"END_COLOR"\n", color_prefix, buffer);
syslog (level, "%s", message.c_str()); syslog (level, "%s%s", prefix, buffer);
if (consoleLog) {
message = color_prefix + message + END_COLOR + "\n";
fprintf (stderr, "%s", message.c_str());
}
} }
void setConsoleLog (bool c) void setConsoleLog (bool c)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment