3 #include "crow/settings.h"
38 virtual void log(std::string message, LogLevel level) = 0;
44 void log(std::string message, LogLevel level)
override
55 case LogLevel::Warning:
61 case LogLevel::Critical:
65 std::cerr << std::string(
"(") + timestamp() + std::string(
") [") + prefix + std::string(
"] ") + message << std::endl;
69 static std::string timestamp()
76 #if defined(_MSC_VER) || defined(__MINGW32__)
77 #ifdef CROW_USE_LOCALTIMEZONE
78 localtime_s(&my_tm, &t);
83 #ifdef CROW_USE_LOCALTIMEZONE
84 localtime_r(&t, &my_tm);
90 size_t sz = strftime(date,
sizeof(date),
"%Y-%m-%d %H:%M:%S", &my_tm);
91 return std::string(date, date + sz);
103 #ifdef CROW_ENABLE_LOGGING
104 if (level_ >= get_current_log_level())
106 get_handler_ref()->log(stringstream_.str(), level_);
113 logger& operator<<(T
const& value)
115 #ifdef CROW_ENABLE_LOGGING
116 if (level_ >= get_current_log_level())
118 stringstream_ << value;
125 static void setLogLevel(LogLevel level) { get_log_level_ref() = level; }
127 static void setHandler(
ILogHandler* handler) { get_handler_ref() = handler; }
129 static LogLevel get_current_log_level() {
return get_log_level_ref(); }
133 static LogLevel& get_log_level_ref()
135 static LogLevel current_level =
static_cast<LogLevel
>(CROW_LOG_LEVEL);
136 return current_level;
141 static ILogHandler* current_handler = &default_handler;
142 return current_handler;
146 std::ostringstream stringstream_;
151 #define CROW_LOG_CRITICAL \
152 if (crow::logger::get_current_log_level() <= crow::LogLevel::Critical) \
153 crow::logger(crow::LogLevel::Critical)
154 #define CROW_LOG_ERROR \
155 if (crow::logger::get_current_log_level() <= crow::LogLevel::Error) \
156 crow::logger(crow::LogLevel::Error)
157 #define CROW_LOG_WARNING \
158 if (crow::logger::get_current_log_level() <= crow::LogLevel::Warning) \
159 crow::logger(crow::LogLevel::Warning)
160 #define CROW_LOG_INFO \
161 if (crow::logger::get_current_log_level() <= crow::LogLevel::Info) \
162 crow::logger(crow::LogLevel::Info)
163 #define CROW_LOG_DEBUG \
164 if (crow::logger::get_current_log_level() <= crow::LogLevel::Debug) \
165 crow::logger(crow::LogLevel::Debug)
The main namespace of the library. In this namespace is defined the most important classes and functi...