@@ -9,10 +9,10 @@ will print something like | |||||
[0.123 debug myfile.cpp:45] error: 67 | [0.123 debug myfile.cpp:45] error: 67 | ||||
*/ | */ | ||||
#define DEBUG(format, ...) rack::logger::log(rack::logger::DEBUG_LEVEL, __FILE__, __LINE__, format, ##__VA_ARGS__) | |||||
#define INFO(format, ...) rack::logger::log(rack::logger::INFO_LEVEL, __FILE__, __LINE__, format, ##__VA_ARGS__) | |||||
#define WARN(format, ...) rack::logger::log(rack::logger::WARN_LEVEL, __FILE__, __LINE__, format, ##__VA_ARGS__) | |||||
#define FATAL(format, ...) rack::logger::log(rack::logger::FATAL_LEVEL, __FILE__, __LINE__, format, ##__VA_ARGS__) | |||||
#define DEBUG(format, ...) rack::logger::log(rack::logger::DEBUG_LEVEL, __FILE__, __LINE__, __FUNCTION__, format, ##__VA_ARGS__) | |||||
#define INFO(format, ...) rack::logger::log(rack::logger::INFO_LEVEL, __FILE__, __LINE__, __FUNCTION__, format, ##__VA_ARGS__) | |||||
#define WARN(format, ...) rack::logger::log(rack::logger::WARN_LEVEL, __FILE__, __LINE__, __FUNCTION__, format, ##__VA_ARGS__) | |||||
#define FATAL(format, ...) rack::logger::log(rack::logger::FATAL_LEVEL, __FILE__, __LINE__, __FUNCTION__, format, ##__VA_ARGS__) | |||||
namespace rack { | namespace rack { | ||||
@@ -35,7 +35,7 @@ void destroy(); | |||||
/** Do not use this function directly. Use the macros above. | /** Do not use this function directly. Use the macros above. | ||||
Thread-safe, meaning messages cannot overlap each other in the log. | Thread-safe, meaning messages cannot overlap each other in the log. | ||||
*/ | */ | ||||
void log(Level level, const char* filename, int line, const char* format, ...); | |||||
void log(Level level, const char* filename, int line, const char* func, const char* format, ...); | |||||
/** Returns whether the current log file failed to end properly, due to a possible crash. | /** Returns whether the current log file failed to end properly, due to a possible crash. | ||||
Must be called *before* init(). | Must be called *before* init(). | ||||
*/ | */ | ||||
@@ -52,7 +52,7 @@ static const int levelColors[] = { | |||||
31 | 31 | ||||
}; | }; | ||||
static void logVa(Level level, const char* filename, int line, const char* format, va_list args) { | |||||
static void logVa(Level level, const char* filename, int line, const char* func, const char* format, va_list args) { | |||||
std::lock_guard<std::mutex> lock(logMutex); | std::lock_guard<std::mutex> lock(logMutex); | ||||
if (!outputFile) | if (!outputFile) | ||||
return; | return; | ||||
@@ -61,7 +61,7 @@ static void logVa(Level level, const char* filename, int line, const char* forma | |||||
double duration = (nowTime - startTime) / 1e9; | double duration = (nowTime - startTime) / 1e9; | ||||
if (outputFile == stderr) | if (outputFile == stderr) | ||||
std::fprintf(outputFile, "\x1B[%dm", levelColors[level]); | std::fprintf(outputFile, "\x1B[%dm", levelColors[level]); | ||||
std::fprintf(outputFile, "[%.03f %s %s:%d] ", duration, levelLabels[level], filename, line); | |||||
std::fprintf(outputFile, "[%.03f %s %s:%d %s] ", duration, levelLabels[level], filename, line, func); | |||||
if (outputFile == stderr) | if (outputFile == stderr) | ||||
std::fprintf(outputFile, "\x1B[0m"); | std::fprintf(outputFile, "\x1B[0m"); | ||||
std::vfprintf(outputFile, format, args); | std::vfprintf(outputFile, format, args); | ||||
@@ -69,10 +69,10 @@ static void logVa(Level level, const char* filename, int line, const char* forma | |||||
std::fflush(outputFile); | std::fflush(outputFile); | ||||
} | } | ||||
void log(Level level, const char* filename, int line, const char* format, ...) { | |||||
void log(Level level, const char* filename, int line, const char* func, const char* format, ...) { | |||||
va_list args; | va_list args; | ||||
va_start(args, format); | va_start(args, format); | ||||
logVa(level, filename, line, format, args); | |||||
logVa(level, filename, line, func, format, args); | |||||
va_end(args); | va_end(args); | ||||
} | } | ||||