2011-07-13 23:12:36 +02:00
|
|
|
#include "logger.h"
|
2011-04-06 21:46:58 +02:00
|
|
|
|
|
|
|
#include <iostream>
|
2011-04-07 10:45:58 +02:00
|
|
|
#include <cstdlib>
|
2010-11-18 23:13:35 +01:00
|
|
|
|
2011-07-13 23:12:36 +02:00
|
|
|
void log(LogLevel level, const std::string& message, const char *trace)
|
2010-11-18 23:13:35 +01:00
|
|
|
{
|
|
|
|
std::string strace;
|
|
|
|
if(trace) {
|
|
|
|
strace = trace;
|
|
|
|
strace = strace.substr(0, strace.find_first_of('('));
|
|
|
|
if(strace.find_last_of(' ') != std::string::npos)
|
|
|
|
strace = strace.substr(strace.find_last_of(' ') + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef linux
|
|
|
|
static char const *colors[] = { "\033[01;31m ", "\033[01;31m", "\033[01;33m", "\033[0;32m", "\033[01;34m" };
|
|
|
|
static bool colored = getenv("COLORED_OUTPUT");
|
|
|
|
if(colored)
|
2010-11-21 22:48:58 +01:00
|
|
|
std::cout << colors[level];
|
2010-11-18 23:13:35 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if(!strace.empty())
|
2010-11-21 22:48:58 +01:00
|
|
|
std::cout << "[" << strace << "] ";
|
2010-11-18 23:13:35 +01:00
|
|
|
|
2011-07-13 23:12:36 +02:00
|
|
|
std::cout << message;
|
2010-11-18 23:13:35 +01:00
|
|
|
|
|
|
|
#ifdef linux
|
|
|
|
if(colored)
|
2010-11-21 22:48:58 +01:00
|
|
|
std::cout << "\033[0m";
|
2010-11-18 23:13:35 +01:00
|
|
|
#endif
|
|
|
|
|
2010-11-21 22:48:58 +01:00
|
|
|
std::cout << std::endl;
|
2010-11-18 23:13:35 +01:00
|
|
|
|
2011-07-13 23:12:36 +02:00
|
|
|
if(level == LogFatal)
|
2010-11-18 23:13:35 +01:00
|
|
|
exit(-1);
|
|
|
|
}
|