Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RLogger.cxx
Go to the documentation of this file.
1/// \file RLogger.cxx
2/// \author Axel Naumann <axel@cern.ch>
3/// \date 2015-07-07
4/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
5/// is welcome!
6
7/*************************************************************************
8 * Copyright (C) 1995-2020, Rene Brun and Fons Rademakers. *
9 * All rights reserved. *
10 * *
11 * For the licensing terms see $ROOTSYS/LICENSE. *
12 * For the list of contributors see $ROOTSYS/README/CREDITS. *
13 *************************************************************************/
14
15#include "ROOT/RLogger.hxx"
16
17#include "TError.h"
18
19#include <algorithm>
20#include <array>
21#include <memory>
22#include <vector>
23
24// pin vtable
26
27namespace {
28class RLogHandlerDefault : public ROOT::RLogHandler {
29public:
30 // Returns false if further emission of this log entry should be suppressed.
31 bool Emit(const ROOT::RLogEntry &entry) override;
32};
33
34inline bool RLogHandlerDefault::Emit(const ROOT::RLogEntry &entry)
35{
36 constexpr static int numLevels = static_cast<int>(ROOT::ELogLevel::kDebug) + 1;
37 int cappedLevel = std::min(static_cast<int>(entry.fLevel), numLevels - 1);
38 constexpr static std::array<const char *, numLevels> sTag{
39 {"{unset-error-level please report}", "FATAL", "Error", "Warning", "Info", "Debug"}};
40
41 std::stringstream strm;
42 auto channel = entry.fChannel;
43 if (channel && !channel->GetName().empty())
44 strm << '[' << channel->GetName() << "] ";
46
47 if (!entry.fLocation.fFile.empty())
48 strm << " " << entry.fLocation.fFile << ':' << entry.fLocation.fLine;
49 if (!entry.fLocation.fFuncName.empty())
50 strm << " in " << entry.fLocation.fFuncName;
51
52 static constexpr const int errorLevelOld[] = {kFatal /*unset*/, kFatal, kError, kWarning, kInfo, kInfo /*debug*/};
54 entry.fMessage.c_str());
55 return true;
56}
57} // unnamed namespace
58
60{
61 static RLogManager instance(std::make_unique<RLogHandlerDefault>());
62 return instance;
63}
64
65std::unique_ptr<ROOT::RLogHandler> ROOT::RLogManager::Remove(RLogHandler *handler)
66{
67 auto iter = std::find_if(fHandlers.begin(), fHandlers.end(), [&](const std::unique_ptr<RLogHandler> &handlerPtr) {
68 return handlerPtr.get() == handler;
69 });
70 if (iter != fHandlers.end()) {
71 std::unique_ptr<RLogHandler> ret;
72 swap(*iter, ret);
73 fHandlers.erase(iter);
74 return ret;
75 }
76 return {};
77}
78
80{
81 auto channel = entry.fChannel;
82
83 Increment(entry.fLevel);
84 if (channel != this)
85 channel->Increment(entry.fLevel);
86
87 // Is there a specific level for the channel? If so, take that,
88 // overruling the global one.
89 if (channel->GetEffectiveVerbosity(*this) < entry.fLevel)
90 return true;
91
92 // Lock-protected extraction of handlers, such that they don't get added during the
93 // handler iteration.
94 std::vector<RLogHandler *> handlers;
95
96 {
97 std::lock_guard<std::mutex> lock(fMutex);
98
99 handlers.resize(fHandlers.size());
100 std::transform(fHandlers.begin(), fHandlers.end(), handlers.begin(),
101 [](const std::unique_ptr<RLogHandler> &handlerUPtr) { return handlerUPtr.get(); });
102 }
103
104 for (auto &&handler : handlers)
105 if (!handler->Emit(entry))
106 return false;
107 return true;
108}
static Roo_reg_AGKInteg1D instance
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
ErrorHandlerFunc_t GetErrorHandler()
Returns the current error handler function.
Definition TError.cxx:102
A diagnostic that can be emitted by the RLogManager.
Definition RLogger.hxx:174
Abstract RLogHandler base class.
Definition RLogger.hxx:81
virtual ~RLogHandler()
Definition RLogger.cxx:25
A RLogHandler that multiplexes diagnostics to different client RLogHandlers and keeps track of the su...
Definition RLogger.hxx:132
std::unique_ptr< RLogHandler > Remove(RLogHandler *handler)
Remove and return the given log handler. Returns nullptr if not found.
Definition RLogger.cxx:65
bool Emit(const RLogEntry &entry) override
Emit a log entry.
Definition RLogger.cxx:79
static RLogManager & Get()
Definition RLogger.cxx:59
@ kInfo
Informational messages; used for instance for tracing.
@ kDebug
Debug information; only useful for developers; can have added verbosity up to 255-kDebug.
@ kError
An error.
@ kFatal
An error which causes further processing to be unreliable.
@ kWarning
Warnings about likely unexpected behavior.