27 namespace Experimental {
32 enum class ELogLevel {
48 virtual ~RLogHandler();
55 virtual bool Emit(
const RLogEntry &entry) = 0;
64 class RLogManager:
public RLogHandler {
66 std::vector<std::unique_ptr<RLogHandler>> fHandlers;
68 long long fNumWarnings{0};
69 long long fNumErrors{0};
72 RLogManager(std::unique_ptr<RLogHandler> &&lh) { fHandlers.emplace_back(std::move(lh)); }
75 static RLogManager &Get();
78 void PushFront(std::unique_ptr<RLogHandler> handler) { fHandlers.insert(fHandlers.begin(), std::move(handler)); }
81 void PushBack(std::unique_ptr<RLogHandler> handler) { fHandlers.emplace_back(std::move(handler)); }
85 bool Emit(
const RLogEntry &entry)
override
87 for (
auto &&handler: fHandlers)
88 if (!handler->Emit(entry))
94 long long GetNumWarnings()
const {
return fNumWarnings; }
97 long long GetNumErrors()
const {
return fNumErrors; }
104 class RLogDiagCounter {
107 long long fInitialWarnings{RLogManager::Get().GetNumWarnings()};
109 long long fInitialErrors{RLogManager::Get().GetNumErrors()};
113 long long GetAccumulatedWarnings()
const {
return RLogManager::Get().GetNumWarnings() - fInitialWarnings; }
116 long long GetAccumulatedErrors()
const {
return RLogManager::Get().GetNumErrors() - fInitialErrors; }
119 bool HasWarningOccurred()
const {
return GetAccumulatedWarnings(); }
122 bool HasErrorOccurred()
const {
return GetAccumulatedErrors(); }
125 bool HasErrorOrWarningOccurred()
const {
return HasWarningOccurred() || HasErrorOccurred(); }
136 class RLogEntry:
public std::ostringstream {
140 std::string fFuncName;
145 RLogEntry() =
default;
146 RLogEntry(ELogLevel level, std::string_view group): fGroup(group), fLevel(level) {}
147 RLogEntry(ELogLevel level, std::string_view group, std::string_view filename,
int line, std::string_view funcname)
148 : fGroup(group), fFile(filename), fFuncName(funcname), fLine(line), fLevel(level)
151 RLogEntry &SetFile(
const std::string &file)
156 RLogEntry &SetFunction(
const std::string &func)
161 RLogEntry &SetLine(
int line)
167 ~RLogEntry() { RLogManager::Get().Emit(*
this); }
173 #if defined(_MSC_VER)
174 #define R__LOG_PRETTY_FUNCTION __FUNCSIG__
176 #define R__LOG_PRETTY_FUNCTION __PRETTY_FUNCTION__
179 #define R__LOG_HERE(LEVEL, GROUP) \
180 ROOT::Experimental::RLogEntry(LEVEL, GROUP).SetFile(__FILE__).SetLine(__LINE__).SetFunction(R__LOG_PRETTY_FUNCTION)
182 #define R__FATAL_HERE(GROUP) R__LOG_HERE(ROOT::Experimental::ELogLevel::kFatal, GROUP)
183 #define R__ERROR_HERE(GROUP) R__LOG_HERE(ROOT::Experimental::ELogLevel::kError, GROUP)
184 #define R__WARNING_HERE(GROUP) R__LOG_HERE(ROOT::Experimental::ELogLevel::kWarning, GROUP)
185 #define R__INFO_HERE(GROUP) R__LOG_HERE(ROOT::Experimental::ELogLevel::kInfo, GROUP)
186 #define R__DEBUG_HERE(GROUP) R__LOG_HERE(ROOT::Experimental::ELogLevel::kDebug, GROUP)