Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
logging.hxx
Go to the documentation of this file.
1///
2/// Basic logging utilities meant to be used by binaries.
3/// Use instead of RLogger for user-facing messages.
4///
5#ifndef ROOT_Main_Logging
6#define ROOT_Main_Logging
7
8#include <iostream>
9
10namespace Detail {
11
12class NullBuf : public std::streambuf {
13public:
14 int overflow(int c) final { return c; }
15};
16
17// A stream that discards all input.
18class NullStream : public std::ostream {
20
21public:
22 NullStream() : std::ostream(&fBuf) {}
23};
24
25inline const char *gLogName = "";
26/// Log verbosity works this way:
27/// If it's <= 0, all warnings are suppressed.
28/// Additionally, when Info(lv) is called, it is only displayed if lv <= LogVerbosity.
29inline int gLogVerbosity = 1;
30
32{
33 static NullStream nullStream;
34 return nullStream;
35}
36
37} // namespace Detail
38
39inline void InitLog(const char *name, int defaultVerbosity = 1)
40{
42 Detail::gLogVerbosity = defaultVerbosity;
43}
44
45inline void SetLogVerbosity(int verbosity)
46{
47 Detail::gLogVerbosity = verbosity;
48}
49
50inline int GetLogVerbosity()
51{
53}
54
55inline std::ostream &Err()
56{
57 std::cerr << "Error in <" << Detail::gLogName << ">: ";
58 return std::cerr;
59}
60
61inline std::ostream &Warn()
62{
63 std::ostream &s = Detail::gLogVerbosity < 1 ? Detail::GetNullStream() : std::cerr;
64 s << "Warning in <" << Detail::gLogName << ">: ";
65 return s;
66}
67
68inline std::ostream &Info(int minLevel)
69{
70 std::ostream &s = Detail::gLogVerbosity < minLevel ? Detail::GetNullStream() : std::cerr;
71 s << "Info in <" << Detail::gLogName << ">: ";
72 return s;
73}
74
75#endif
#define c(i)
Definition RSha256.hxx:101
char name[80]
Definition TGX11.cxx:148
int overflow(int c) final
Definition logging.hxx:14
STL class.
void SetLogVerbosity(int verbosity)
Definition logging.hxx:45
int GetLogVerbosity()
Definition logging.hxx:50
std::ostream & Warn()
Definition logging.hxx:61
void InitLog(const char *name, int defaultVerbosity=1)
Definition logging.hxx:39
std::ostream & Info(int minLevel)
Definition logging.hxx:68
std::ostream & Err()
Definition logging.hxx:55
Basic logging utilities meant to be used by binaries.
Definition logging.hxx:10
NullStream & GetNullStream()
Definition logging.hxx:31
const char * gLogName
Definition logging.hxx:25
int gLogVerbosity
Log verbosity works this way: If it's <= 0, all warnings are suppressed.
Definition logging.hxx:29
TSpectrum2 * s
Definition peaks2.C:33