Logo ROOT   6.14/05
Reference Guide
TLogger.cxx
Go to the documentation of this file.
1 /// \file TLogger.cxx
2 /// \ingroup Base ROOT7
3 /// \author Axel Naumann <axel@cern.ch>
4 /// \date 2015-07-07
5 /// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
6 /// is welcome!
7 
8 /*************************************************************************
9  * Copyright (C) 1995-2015, Rene Brun and Fons Rademakers. *
10  * All rights reserved. *
11  * *
12  * For the licensing terms see $ROOTSYS/LICENSE. *
13  * For the list of contributors see $ROOTSYS/README/CREDITS. *
14  *************************************************************************/
15 
16 #include "ROOT/TLogger.hxx"
17 #include <iostream>
18 #include <sstream>
19 
20 #include "TError.h"
21 
22 // pin vtable
24 
25 namespace {
26 class TLogHandlerDefault: public ROOT::Experimental::TLogHandler {
27 public:
28  // Returns false if further emission of this log entry should be suppressed.
29  bool Emit(const ROOT::Experimental::TLogEntry &entry) override;
30 };
31 
32 bool TLogHandlerDefault::Emit(const ROOT::Experimental::TLogEntry &entry)
33 {
34  constexpr static std::array<const char *, 5> sTag{{"Debug", "Info", "Warning", "Log", "FATAL"}};
35  std::stringstream strm;
36  strm << "ROOT ";
37  if (!entry.fGroup.empty())
38  strm << '[' << entry.fGroup << "] ";
39  strm << sTag[static_cast<int>(entry.fLevel)];
40 
41  if (!entry.fFile.empty())
42  strm << " " << entry.fFile << ':' << entry.fLine;
43  if (!entry.fFuncName.empty())
44  strm << " in " << entry.fFuncName;
45 
46  static constexpr const int errorLevelOld[] = {0, 1000, 2000, 3000, 6000};
47  (*::GetErrorHandler())(errorLevelOld[static_cast<int>(entry.fLevel)],
49  strm.str().c_str(), entry.str().c_str());
50  return true;
51 }
52 } // unnamed namespace
53 
55 {
56  static TLogManager instance(std::make_unique<TLogHandlerDefault>());
57  return instance;
58 }
virtual bool Emit(const TLogEntry &entry)=0
Emit a log entry.
A TLogHandler that multiplexes diagnostics to different client TLogHandlers.
Definition: TLogger.hxx:63
A diagnostic, emitted by the TLogManager upon destruction of the TLogEntry.
Definition: TLogger.hxx:135
static TLogManager & Get()
Definition: TLogger.cxx:54
Abstract TLogHandler base class.
Definition: TLogger.hxx:45
ErrorHandlerFunc_t GetErrorHandler()
Returns the current error handler function.
Definition: TError.cxx:116