Orbit Framework
An ultra-modern, asynchronous, cross-platform C++ Web Framework.
Loading...
Searching...
No Matches
Logger.hpp
Go to the documentation of this file.
1#pragma once
2#ifdef _WIN32
3#undef ERROR
4#endif
5#include <string>
6#include <iostream>
7#include <sstream>
8#include <mutex>
9
10namespace utils {
11
12enum class LogLevel {
13 DEBUG = 0,
14 INFO = 1,
15 WARN = 2,
16 ERROR = 3
17};
18
19class Logger {
20public:
21 static void init(const std::string& level_str);
22 static void log(LogLevel level, const char* file, int line, const std::string& msg);
23
25private:
26 static std::mutex log_mutex;
27 static std::string level_to_string(LogLevel level);
28};
29
30} // namespace utils
31
32#define LOG_DEBUG(msg) do { if (utils::Logger::current_level <= utils::LogLevel::DEBUG) { std::ostringstream oss; oss << msg; utils::Logger::log(utils::LogLevel::DEBUG, __FILE__, __LINE__, oss.str()); } } while(0)
33#define LOG_INFO(msg) do { if (utils::Logger::current_level <= utils::LogLevel::INFO) { std::ostringstream oss; oss << msg; utils::Logger::log(utils::LogLevel::INFO, __FILE__, __LINE__, oss.str()); } } while(0)
34#define LOG_WARN(msg) do { if (utils::Logger::current_level <= utils::LogLevel::WARN) { std::ostringstream oss; oss << msg; utils::Logger::log(utils::LogLevel::WARN, __FILE__, __LINE__, oss.str()); } } while(0)
35#define LOG_ERROR(msg) do { if (utils::Logger::current_level <= utils::LogLevel::ERROR) { std::ostringstream oss; oss << msg; utils::Logger::log(utils::LogLevel::ERROR, __FILE__, __LINE__, oss.str()); } } while(0)
Definition Logger.hpp:19
static LogLevel current_level
Definition Logger.hpp:24
static void init(const std::string &level_str)
Definition Logger.cpp:10
static void log(LogLevel level, const char *file, int line, const std::string &msg)
Definition Logger.cpp:27
Definition CaseInsensitive.hpp:7
LogLevel
Definition Logger.hpp:12