#ifndef SIRIUS_UTILS_LOG_H_
#define SIRIUS_UTILS_LOG_H_
#include <string>
#ifdef SIRIUS_ENABLE_LOGS
#include <map>
#include <memory>
#include <mutex>
#include <spdlog/spdlog.h>
namespace sirius {
namespace utils {
class LoggerManager {
public:
using Logger = spdlog::logger;
using LoggerSPtr = std::shared_ptr<Logger>;
public:
static LoggerManager& Instance();
void SetLogLevel(spdlog::level::level_enum level);
Logger* Get(const std::string& channel);
private:
LoggerManager() = default;
private:
std::mutex loggers_mutex_;
std::map<std::string, LoggerSPtr> loggers_;
spdlog::level::level_enum log_level_{spdlog::level::info};
};
} // namespace utils
} // namespace sirius
#define LOG_SET_LEVEL_ENUM(lvl_enum) \
sirius::utils::LoggerManager::Instance().SetLogLevel(lvl_enum)
#define LOG_SET_LEVEL(lvl) LOG_SET_LEVEL_ENUM(spdlog::level::lvl)
#define LOG(channel, level, ...) \
sirius::utils::LoggerManager::Instance().Get(channel)->level(__VA_ARGS__)
#else
#define LOG_SET_LEVEL_ENUM(lvl_enum)
#define LOG_SET_LEVEL(lvl)
#define LOG(channel, level, ...)
#endif // SIRIUS_ENABLE_LOGS
namespace sirius {
namespace utils {
void SetVerbosityLevel(const std::string& level);
} // namespace utils
} // namespace sirius
#endif // SIRIUS_UTILS_LOG_H_