11#include "absl/strings/str_cat.h"
12#include "absl/strings/str_format.h"
13#include "absl/strings/string_view.h"
51 const std::set<std::string>& categories);
59 void log(
LogLevel level, absl::string_view category,
60 absl::string_view message);
72 return level >=
min_level_.load(std::memory_order_relaxed);
123#define YAZE_LOG_IMPL(level, category, format, ...) \
125 auto&& yaze_log_category_ = (category); \
126 auto& yaze_log_manager_ = ::yaze::util::LogManager::instance(); \
127 if (yaze_log_manager_.ShouldLog(level, yaze_log_category_)) { \
128 yaze_log_manager_.log(level, yaze_log_category_, \
129 absl::StrFormat(format, ##__VA_ARGS__)); \
133#define LOG_DEBUG(category, format, ...) \
134 YAZE_LOG_IMPL(yaze::util::LogLevel::YAZE_DEBUG, category, format, \
136#define LOG_INFO(category, format, ...) \
137 YAZE_LOG_IMPL(yaze::util::LogLevel::INFO, category, format, ##__VA_ARGS__)
138#define LOG_WARN(category, format, ...) \
139 YAZE_LOG_IMPL(yaze::util::LogLevel::WARNING, category, format, ##__VA_ARGS__)
140#define LOG_ERROR(category, format, ...) \
141 YAZE_LOG_IMPL(yaze::util::LogLevel::ERROR, category, format, ##__VA_ARGS__)
142#define LOG_FATAL(category, format, ...) \
143 YAZE_LOG_IMPL(yaze::util::LogLevel::FATAL, category, format, ##__VA_ARGS__)
145template <
typename... Args>
146inline void logf(
const absl::FormatSpec<Args...>& format, Args&&... args) {
149 absl::StrFormat(format, std::forward<Args>(args)...));
152inline void logf(absl::string_view message) {
A singleton that manages all logging configuration and output.
std::ofstream log_stream_
std::set< std::string, std::less<> > enabled_categories_
static LogManager & instance()
void configure(LogLevel level, const std::string &file_path, const std::set< std::string > &categories)
Configures the logging system.
std::string log_file_path_
void DisableDebugLogging()
std::set< std::string, std::less<> > disabled_categories_
void operator=(const LogManager &)=delete
void EnableDebugLogging()
Toggle debug logging on/off at runtime.
LogLevel GetLogLevel() const
std::atomic< bool > all_categories_enabled_
std::atomic< LogLevel > min_level_
void Flush()
Writes buffered file output now. log() flushes warnings and errors at once but batches other lines fo...
bool ShouldLog(LogLevel level) const
Fast inline check if logging is enabled for the given level.
void SetLogLevel(LogLevel level)
Runtime log level control (for debug card)
void log(LogLevel level, absl::string_view category, absl::string_view message)
The primary logging function.
LogManager(const LogManager &)=delete
bool IsDebugEnabled() const
LogLevel
Defines the severity levels for log messages. This allows for filtering messages based on their impor...
void logf(const absl::FormatSpec< Args... > &format, Args &&... args)