|
@@ -10,9 +10,28 @@
|
|
|
#include <cassert>
|
|
#include <cassert>
|
|
|
#include <ctime>
|
|
#include <ctime>
|
|
|
|
|
|
|
|
|
|
+#include <boost/preprocessor/seq/for_each.hpp>
|
|
|
|
|
+#include <boost/preprocessor/variadic/to_seq.hpp>
|
|
|
|
|
+
|
|
|
#include "logger/exception.h"
|
|
#include "logger/exception.h"
|
|
|
#include "logger/logpacket.h"
|
|
#include "logger/logpacket.h"
|
|
|
|
|
|
|
|
|
|
+#define STRING2(A) #A
|
|
|
|
|
+#define STRING(A) STRING2(A)
|
|
|
|
|
+#define TO_SEQ(...) BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__)
|
|
|
|
|
+#define FOR_EACH(F, DATA, SEQ) BOOST_PP_SEQ_FOR_EACH(F, DATA, SEQ)
|
|
|
|
|
+#define APPLY(F, ...) FOR_EACH(F, _, TO_SEQ(__VA_ARGS__))
|
|
|
|
|
+
|
|
|
|
|
+#define FROM_STRING(r, data, token) \
|
|
|
|
|
+ if (lower_case == STRING(token)) \
|
|
|
|
|
+ return level::token; \
|
|
|
|
|
+ else
|
|
|
|
|
+
|
|
|
|
|
+#define TO_STRING(r, data, token) \
|
|
|
|
|
+ if (lvl == level::token) \
|
|
|
|
|
+ return STRING(token); \
|
|
|
|
|
+ else
|
|
|
|
|
+
|
|
|
namespace logging {
|
|
namespace logging {
|
|
|
timeval now() {
|
|
timeval now() {
|
|
|
struct timeval tv;
|
|
struct timeval tv;
|
|
@@ -20,28 +39,18 @@ namespace logging {
|
|
|
return tv;
|
|
return tv;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-#define X(token) \
|
|
|
|
|
- if (lower_case == #token) \
|
|
|
|
|
- return level::token; \
|
|
|
|
|
- else
|
|
|
|
|
level level_from_string(std::string const & str) {
|
|
level level_from_string(std::string const & str) {
|
|
|
std::string lower_case;
|
|
std::string lower_case;
|
|
|
std::transform(str.begin(), str.end(), std::back_inserter(lower_case),
|
|
std::transform(str.begin(), str.end(), std::back_inserter(lower_case),
|
|
|
&tolower);
|
|
&tolower);
|
|
|
- LIST_OF_LOGGING_LEVELS
|
|
|
|
|
|
|
+ APPLY(FROM_STRING, LIST_OF_LOGGING_LEVELS)
|
|
|
throw invalid_property{str + " is not a log level"};
|
|
throw invalid_property{str + " is not a log level"};
|
|
|
}
|
|
}
|
|
|
-#undef X
|
|
|
|
|
|
|
|
|
|
-#define X(token) \
|
|
|
|
|
- if (lvl == level::token) \
|
|
|
|
|
- return #token; \
|
|
|
|
|
- else
|
|
|
|
|
char const * level_to_string(level lvl) {
|
|
char const * level_to_string(level lvl) {
|
|
|
- LIST_OF_LOGGING_LEVELS
|
|
|
|
|
|
|
+ APPLY(TO_STRING, LIST_OF_LOGGING_LEVELS)
|
|
|
throw std::domain_error{"unknown logging level in switch"};
|
|
throw std::domain_error{"unknown logging level in switch"};
|
|
|
}
|
|
}
|
|
|
-#undef X
|
|
|
|
|
|
|
|
|
|
std::string to_string(level lvl, bool uppercase) {
|
|
std::string to_string(level lvl, bool uppercase) {
|
|
|
std::string str = level_to_string(lvl);
|
|
std::string str = level_to_string(lvl);
|