3 #include <spdlog/sinks/stdout_color_sinks.h>
4 #include <spdlog/spdlog.h>
10 const char* val = std::getenv(
"WMTK_LOGGER_LEVEL");
14 std::string env_val = val;
15 return !env_val.empty();
21 const char* val = std::getenv(
"WMTK_LOGGER_LEVEL");
25 std::string env_val = val;
26 if (!env_val.empty()) {
27 auto level = spdlog::level::from_str(env_val);
28 if (level == spdlog::level::off) {
29 if (env_val !=
"off") {
32 "Unknown logger level due to env value WMTK_LOGGER_LEVEL={}!",
42 std::shared_ptr<spdlog::logger>& get_shared_logger()
44 static std::shared_ptr<spdlog::logger>
logger;
49 std::shared_ptr<spdlog::logger>& get_shared_opt_logger()
51 static std::shared_ptr<spdlog::logger>
logger;
60 if (
auto l = get_shared_logger(); bool(l)) {
67 static auto default_logger = spdlog::stdout_color_mt(
"wmtk");
68 load_env_levels(*default_logger);
70 return *default_logger;
77 if (get_shared_opt_logger()) {
78 return *get_shared_opt_logger();
84 static auto default_logger = spdlog::stdout_color_mt(
"wmtk-opt");
85 return *default_logger;
92 get_shared_logger() = std::move(x);
98 get_shared_opt_logger() = std::move(x);
104 throw std::runtime_error(msg);
void set_opt_logger(std::shared_ptr< spdlog::logger > x)
Setup a logger object to be used by WildmeshToolkit optimization.
bool has_user_overloaded_logger_level()
void set_logger(std::shared_ptr< spdlog::logger > x)
Setup a logger object to be used by WildmeshToolkit.
void log_and_throw_error(const std::string &msg)
spdlog::logger & logger()
Retrieves the current logger.
spdlog::logger & opt_logger()
Retrieves the logger for the optimization.