EICrecon
JANA based reconstruction for the EPIC detector
Loading...
Searching...
No Matches
SpdlogExtensions.h
Go to the documentation of this file.
1// Created by Dmitry Romanov
2// Subject to the terms in the LICENSE file found in the top-level directory.
3//
4
5#pragma once
6
7#include <spdlog/spdlog.h>
8#include <spdlog/fmt/fmt.h>
9#include <stdexcept>
10
11namespace eicrecon {
12inline spdlog::level::level_enum ParseLogLevel(const std::string& input) {
13
14 // Convert the source string to lower case
15 std::string lc_input; // Lower case input
16 lc_input.resize(input.size());
17 std::transform(input.begin(), input.end(), lc_input.begin(), ::tolower);
18
19 if (lc_input == "trace" || lc_input == std::to_string(SPDLOG_LEVEL_TRACE))
20 return spdlog::level::trace;
21 if (lc_input == "debug" || lc_input == std::to_string(SPDLOG_LEVEL_DEBUG))
22 return spdlog::level::debug;
23 if (lc_input == "info" || lc_input == std::to_string(SPDLOG_LEVEL_INFO))
24 return spdlog::level::info;
25 if (lc_input == "warn" || lc_input == "warning" || lc_input == std::to_string(SPDLOG_LEVEL_WARN))
26 return spdlog::level::warn;
27 if (lc_input == "err" || lc_input == "error" || lc_input == std::to_string(SPDLOG_LEVEL_ERROR))
28 return spdlog::level::err;
29 if (lc_input == "critical" || lc_input == std::to_string(SPDLOG_LEVEL_CRITICAL))
30 return spdlog::level::critical;
31 if (lc_input == "off" || lc_input == std::to_string(SPDLOG_LEVEL_OFF))
32 return spdlog::level::off;
33
34 auto err_msg = fmt::format("ParseLogLevel can't parse input string: '{}'", input);
35 throw std::runtime_error(err_msg);
36}
37
38inline std::string LogLevelToString(spdlog::level::level_enum input) {
39
40 // Convert the source string to lower case
41 switch (input) {
42 case spdlog::level::trace:
43 return "trace";
44 case spdlog::level::debug:
45 return "debug";
46 case spdlog::level::info:
47 return "info";
48 case spdlog::level::warn:
49 return "warn";
50 case spdlog::level::err:
51 return "error";
52 case spdlog::level::critical:
53 return "critical";
54 case spdlog::level::off:
55 return "off";
56 case spdlog::level::n_levels:
57 [[fallthrough]];
58 default:
59 break;
60 }
61
62 auto err_msg =
63 fmt::format("LogLevelToString doesn't know this log level: '{}'", fmt::underlying(input));
64 throw std::runtime_error(err_msg);
65}
66} // namespace eicrecon
-client
Definition CalorimeterClusterRecoCoG.cc:37
spdlog::level::level_enum ParseLogLevel(const std::string &input)
Definition SpdlogExtensions.h:12
std::string LogLevelToString(spdlog::level::level_enum input)
Definition SpdlogExtensions.h:38