Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
RLogger.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/RLogger.hxx"
17 #include <iostream>
18 #include <sstream>
19 
20 #include "TError.h"
21 
22 // pin vtable
23 ROOT::Experimental::RLogHandler::~RLogHandler() {}
24 
25 namespace {
26 class RLogHandlerDefault: public ROOT::Experimental::RLogHandler {
27 public:
28  // Returns false if further emission of this log entry should be suppressed.
29  bool Emit(const ROOT::Experimental::RLogEntry &entry) override;
30 };
31 
32 bool RLogHandlerDefault::Emit(const ROOT::Experimental::RLogEntry &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)],
48  entry.fLevel == ROOT::Experimental::ELogLevel::kFatal,
49  strm.str().c_str(), entry.str().c_str());
50  return true;
51 }
52 } // unnamed namespace
53 
54 ROOT::Experimental::RLogManager &ROOT::Experimental::RLogManager::Get()
55 {
56  static RLogManager instance(std::make_unique<RLogHandlerDefault>());
57  return instance;
58 }