//#define SPDLOG_FMT_EXTERNAL #include #include #include #include #include #include #include namespace simpleengine::log { class Logger { private: std::shared_ptr inner; public: Logger(std::string name) { inner = spdlog::get(name); if (!inner) { inner = spdlog::stderr_color_mt(name); } } Logger(std::shared_ptr logger) : inner(logger) { } std::shared_ptr get_inner() { return inner; } void set_level(spdlog::level::level_enum lvl) { inner->set_level(lvl); } void log(spdlog::level::level_enum lvl, spdlog::string_view_t msg) { inner->log(spdlog::source_loc{}, lvl, msg); } template void trace(const T &msg) { log(spdlog::level::trace, msg); } template void debug(const T &msg) { log(spdlog::level::debug, msg); } template void info(const T &msg) { log(spdlog::level::info, msg); } template void warn(const T &msg) { log(spdlog::level::warn, msg); } template void error(const T &msg) { log(spdlog::level::err, msg); } template void critical(const T &msg) { log(spdlog::level::critical, msg); } template void trace(spdlog::format_string_t fmt, Args &&... args) { log(spdlog::level::trace, fmt, std::forward(args)...); } template void debug(spdlog::format_string_t fmt, Args &&... args) { log(spdlog::level::debug, fmt, std::forward(args)...); } template void info(spdlog::format_string_t fmt, Args &&... args) { log(spdlog::level::info, fmt, std::forward(args)...); } template void warn(spdlog::format_string_t fmt, Args &&... args) { log(spdlog::level::warn, fmt, std::forward(args)...); } template void error(spdlog::format_string_t fmt, Args &&... args) { log(spdlog::level::err, fmt, std::forward(args)...); } template void critical(spdlog::format_string_t fmt, Args &&... args) { log(spdlog::level::critical, fmt, std::forward(args)...); } }; using LoggerPtr = std::shared_ptr; class LoggerManager { private: static std::shared_ptr core_logger; public: /* LoggerManager() { spdlog::set_pattern("[%R - %D] [%l] [thread %t] [%n] %v"); core_logger = std::make_shared("Engine"); } */ static void init(); static void set_level(spdlog::level::level_enum lvl); static std::shared_ptr get_core_logger(); static Logger create_logger(std::string name); static Logger get_logger(std::string name); }; }