You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.2 KiB
48 lines
1.2 KiB
#ifndef _LOG_INTERNAL_
|
|
#define _LOG_INTERNAL_
|
|
|
|
// Internal formatting functions
|
|
|
|
#include <log/common.hpp>
|
|
|
|
#include <unordered_map>
|
|
#include <iostream>
|
|
|
|
namespace log {
|
|
namespace internal {
|
|
extern Level level;
|
|
extern int group;
|
|
|
|
const std::unordered_map<Level, std::string> LEVEL_LABELS {
|
|
{ LDEBUG, "LDB" },
|
|
{ DEBUG, "DEB" },
|
|
{ INFO, "INF" },
|
|
{ WARNING, "WAR" },
|
|
{ ERROR, "ERR" },
|
|
{ CRITICAL, "CRI" }
|
|
};
|
|
|
|
void printFormatted(const char * format);
|
|
|
|
template<typename T, typename... Ts>
|
|
void printFormatted(const char * format, const T & first, const Ts & ... rest) {
|
|
// Iterate characters in (rest of) format string
|
|
for (; *format != '\0'; ++format) {
|
|
// Check for placeholder character
|
|
if (*format == '%') {
|
|
// Output first parameter
|
|
std::cerr << first;
|
|
|
|
// Tail recurseion with rest of string and parameters
|
|
printFormatted(format + 1, rest...);
|
|
return;
|
|
}
|
|
|
|
// If not found, output unformatted character
|
|
std::cerr << *format;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#endif |