File indexing completed on 2025-01-18 09:55:43
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)) return spdlog::level::trace;
0020 if(lc_input == "debug" || lc_input == std::to_string(SPDLOG_LEVEL_DEBUG)) return spdlog::level::debug;
0021 if(lc_input == "info" || lc_input == std::to_string(SPDLOG_LEVEL_INFO)) return spdlog::level::info;
0022 if(lc_input == "warn" || lc_input == "warning" || lc_input == std::to_string(SPDLOG_LEVEL_WARN)) return spdlog::level::warn;
0023 if(lc_input == "err" || lc_input == "error" || lc_input == std::to_string(SPDLOG_LEVEL_ERROR)) return spdlog::level::err;
0024 if(lc_input == "critical" || lc_input == std::to_string(SPDLOG_LEVEL_CRITICAL)) return spdlog::level::critical;
0025 if(lc_input == "off" || lc_input == std::to_string(SPDLOG_LEVEL_OFF)) return spdlog::level::off;
0026
0027 auto err_msg = fmt::format("ParseLogLevel can't parse input string: '{}'", input);
0028 throw JException(err_msg);
0029 }
0030
0031 inline std::string LogLevelToString(spdlog::level::level_enum input) {
0032
0033
0034 switch (input) {
0035 case spdlog::level::trace:
0036 return "trace";
0037 case spdlog::level::debug:
0038 return "debug";
0039 case spdlog::level::info:
0040 return "info";
0041 case spdlog::level::warn:
0042 return "warn";
0043 case spdlog::level::err:
0044 return "error";
0045 case spdlog::level::critical:
0046 return "critical";
0047 case spdlog::level::off:
0048 return "off";
0049 case spdlog::level::n_levels:
0050 [[fallthrough]];
0051 default:
0052 break;
0053 }
0054
0055 auto err_msg = fmt::format("ParseLogLevel don't know this log level: '{}'", fmt::underlying(input));
0056 throw JException(err_msg);
0057 }
0058 }