Browse Source

Add function name to logger.

tags/v2.0.0
Andrew Belt 4 years ago
parent
commit
a808849a26
2 changed files with 9 additions and 9 deletions
  1. +5
    -5
      include/logger.hpp
  2. +4
    -4
      src/logger.cpp

+ 5
- 5
include/logger.hpp View File

@@ -9,10 +9,10 @@ will print something like

[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 {
@@ -35,7 +35,7 @@ void destroy();
/** Do not use this function directly. Use the macros above.
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.
Must be called *before* init().
*/


+ 4
- 4
src/logger.cpp View File

@@ -52,7 +52,7 @@ static const int levelColors[] = {
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);
if (!outputFile)
return;
@@ -61,7 +61,7 @@ static void logVa(Level level, const char* filename, int line, const char* forma
double duration = (nowTime - startTime) / 1e9;
if (outputFile == stderr)
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)
std::fprintf(outputFile, "\x1B[0m");
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);
}

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_start(args, format);
logVa(level, filename, line, format, args);
logVa(level, filename, line, func, format, args);
va_end(args);
}



Loading…
Cancel
Save