File indexing completed on 2025-07-05 08:52:41
0001
0002
0003
0004
0005 #pragma once
0006
0007 #include <spdlog/spdlog.h>
0008 #include <spdlog/fmt/fmt.h>
0009 #include <JANA/JException.h>
0010
0011 namespace eicrecon {
0012 inline spdlog::level::level_enum ParseLogLevel(const std::string& input) {
0013
0014
0015 std::string lc_input;
0016 lc_input.resize(input.size());
0017 std::transform(input.begin(), input.end(), lc_input.begin(), ::tolower);
0018
0019 if (lc_input == "trace" || lc_input == std::to_string(SPDLOG_LEVEL_TRACE))
0020 return spdlog::level::trace;
0021 if (lc_input == "debug" || lc_input == std::to_string(SPDLOG_LEVEL_DEBUG))
0022 return spdlog::level::debug;
0023 if (lc_input == "info" || lc_input == std::to_string(SPDLOG_LEVEL_INFO))
0024 return spdlog::level::info;
0025 if (lc_input == "warn" || lc_input == "warning" || lc_input == std::to_string(SPDLOG_LEVEL_WARN))
0026 return spdlog::level::warn;
0027 if (lc_input == "err" || lc_input == "error" || lc_input == std::to_string(SPDLOG_LEVEL_ERROR))
0028 return spdlog::level::err;
0029 if (lc_input == "critical" || lc_input == std::to_string(SPDLOG_LEVEL_CRITICAL))
0030 return spdlog::level::critical;
0031 if (lc_input == "off" || lc_input == std::to_string(SPDLOG_LEVEL_OFF))
0032 return spdlog::level::off;
0033
0034 auto err_msg = fmt::format("ParseLogLevel can't parse input string: '{}'", input);
0035 throw JException(err_msg);
0036 }
0037
0038 inline std::string LogLevelToString(spdlog::level::level_enum input) {
0039
0040
0041 switch (input) {
0042 case spdlog::level::trace:
0043 return "trace";
0044 case spdlog::level::debug:
0045 return "debug";
0046 case spdlog::level::info:
0047 return "info";
0048 case spdlog::level::warn:
0049 return "warn";
0050 case spdlog::level::err:
0051 return "error";
0052 case spdlog::level::critical:
0053 return "critical";
0054 case spdlog::level::off:
0055 return "off";
0056 case spdlog::level::n_levels:
0057 [[fallthrough]];
0058 default:
0059 break;
0060 }
0061
0062 auto err_msg =
0063 fmt::format("ParseLogLevel don't know this log level: '{}'", fmt::underlying(input));
0064 throw JException(err_msg);
0065 }
0066 }