ATLAS Offline Software
Loading...
Searching...
No Matches
Root::TMsgLogger Class Reference

#include <TMsgLogger.h>

Inheritance diagram for Root::TMsgLogger:
Collaboration diagram for Root::TMsgLogger:

Public Member Functions

 TMsgLogger (const TObject *source, TMsgLevel minLevel=kINFO)
 TMsgLogger (const std::string &source, TMsgLevel minLevel=kINFO)
 TMsgLogger (TMsgLevel minLevel=kINFO)
 TMsgLogger (const TMsgLogger &parent)
virtual ~TMsgLogger ()
void SetSource (const char *source)
void SetSource (const std::string &source)
void SetSource (const TString &source)
const std::string & GetSource () const
UInt_t GetMaxSourceSize () const
std::string GetPrintedSource () const
std::string GetFormattedSource () const
TMsgLevel GetMinLevel () const
const std::string & GetMinLevelStr () const
TMsgLevel MapLevel (const TString &instr) const
TMsgLoggeroperator= (const TMsgLogger &parent)
TMsgLoggeroperator<< (TMsgLogger &(*_f)(TMsgLogger &))
TMsgLoggeroperator<< (std::ostream &(*_f)(std::ostream &))
TMsgLoggeroperator<< (std::ios &(*_f)(std::ios &))
TMsgLoggeroperator<< (TMsgLevel level)
template<class T>
TMsgLoggeroperator<< (T arg)

Static Public Member Functions

static TMsgLoggerendmsg (TMsgLogger &logger)
static void SetMinLevel (TMsgLevel minLevel)

Private Member Functions

void Send ()
void InitMaps ()
void WriteMsg (TMsgLevel level, const std::string &line) const

Private Attributes

const TObject * m_objSource
std::string m_strSource
const std::string m_prefix
const std::string m_suffix
TMsgLevel m_activeLevel
const std::string::size_type m_maxSourceSize
std::map< TMsgLevel, std::string > m_levelMap
std::map< TMsgLevel, std::string > m_colorMap

Static Private Attributes

static std::atomic< TMsgLevelm_minLevel = kINFO

Detailed Description

Definition at line 47 of file TMsgLogger.h.

Constructor & Destructor Documentation

◆ TMsgLogger() [1/4]

Root::TMsgLogger::TMsgLogger ( const TObject * source,
TMsgLevel minLevel = kINFO )

Definition at line 42 of file TMsgLogger.cxx.

43 : m_objSource( source ),
44 m_strSource( "" ),
45 m_prefix( PREFIX ),
46 m_suffix( SUFFIX ),
49{
50 // constructor
51 InitMaps();
52}
static const string SUFFIX
static const string::size_type MAXIMUM_SOURCE_NAME_LENGTH
static const string PREFIX
const std::string m_prefix
Definition TMsgLogger.h:108
const std::string m_suffix
Definition TMsgLogger.h:109
const TObject * m_objSource
Definition TMsgLogger.h:106
std::string m_strSource
Definition TMsgLogger.h:107
TMsgLevel m_activeLevel
Definition TMsgLogger.h:110
const std::string::size_type m_maxSourceSize
Definition TMsgLogger.h:111
@ kINFO
Definition TMsgLogger.h:40

◆ TMsgLogger() [2/4]

Root::TMsgLogger::TMsgLogger ( const std::string & source,
TMsgLevel minLevel = kINFO )

Definition at line 54 of file TMsgLogger.cxx.

55 : m_objSource( 0 ),
56 m_strSource( source ),
57 m_prefix( PREFIX ),
58 m_suffix( SUFFIX ),
61{
62 // constructor
63 InitMaps();
64}

◆ TMsgLogger() [3/4]

Root::TMsgLogger::TMsgLogger ( TMsgLevel minLevel = kINFO)

Definition at line 66 of file TMsgLogger.cxx.

67 : m_objSource( 0 ),
68 m_strSource( "Unknown" ),
69 m_prefix( PREFIX ),
70 m_suffix( SUFFIX ),
73{
74 // constructor
75 InitMaps();
76}

◆ TMsgLogger() [4/4]

Root::TMsgLogger::TMsgLogger ( const TMsgLogger & parent)

Definition at line 78 of file TMsgLogger.cxx.

79 : basic_ios< TMsgLogger::char_type, TMsgLogger::traits_type >(),
80 ostringstream(),
81 TObject(),
82 m_prefix( PREFIX ),
85{
86 InitMaps();
87 *this = parent;
88}

◆ ~TMsgLogger()

Root::TMsgLogger::~TMsgLogger ( )
virtual

Definition at line 90 of file TMsgLogger.cxx.

91{}

Member Function Documentation

◆ endmsg()

Root::TMsgLogger & Root::TMsgLogger::endmsg ( TMsgLogger & logger)
static

Definition at line 183 of file TMsgLogger.cxx.

184{
185 // end line
186 logger.Send();
187 return logger;
188}
static Root::TMsgLogger logger("iLumiCalc")

◆ GetFormattedSource()

string Root::TMsgLogger::GetFormattedSource ( ) const

Definition at line 104 of file TMsgLogger.cxx.

105{
106 // make sure the source name is no longer than m_maxSourceSize:
107 string source_name;
108 if (m_objSource) source_name = m_objSource->GetName();
109 else source_name = m_strSource;
110
111 if (source_name.size() > m_maxSourceSize) {
112 source_name.resize(m_maxSourceSize - 3 );
113 source_name += "...";
114 }
115
116 return source_name;
117}

◆ GetMaxSourceSize()

UInt_t Root::TMsgLogger::GetMaxSourceSize ( ) const
inline

Definition at line 63 of file TMsgLogger.h.

63{ return (UInt_t)m_maxSourceSize; }

◆ GetMinLevel()

TMsgLevel Root::TMsgLogger::GetMinLevel ( ) const
inline

Definition at line 67 of file TMsgLogger.h.

67{ return m_minLevel; }
static std::atomic< TMsgLevel > m_minLevel
Definition TMsgLogger.h:99

◆ GetMinLevelStr()

const std::string & Root::TMsgLogger::GetMinLevelStr ( ) const
inline

Definition at line 68 of file TMsgLogger.h.

68{ return m_levelMap.find( m_minLevel )->second; }
std::map< TMsgLevel, std::string > m_levelMap
Definition TMsgLogger.h:113

◆ GetPrintedSource()

string Root::TMsgLogger::GetPrintedSource ( ) const

Definition at line 119 of file TMsgLogger.cxx.

120{
121 // the full logger prefix
122 string source_name = GetFormattedSource();
123 if (source_name.size() < m_maxSourceSize)
124 for (string::size_type i=source_name.size(); i<m_maxSourceSize; i++) source_name.push_back( ' ' );
125
126 return m_prefix + source_name + m_suffix;
127}
std::string GetFormattedSource() const

◆ GetSource()

const std::string & Root::TMsgLogger::GetSource ( ) const
inline

Definition at line 61 of file TMsgLogger.h.

61{ return m_strSource; }

◆ InitMaps()

void Root::TMsgLogger::InitMaps ( )
private

Definition at line 207 of file TMsgLogger.cxx.

208{
209 m_levelMap[kVERBOSE] = "VERBOSE";
210 m_levelMap[kDEBUG] = "DEBUG";
211 m_levelMap[kINFO] = "INFO";
212 m_levelMap[kWARNING] = "WARNING";
213 m_levelMap[kERROR] = "ERROR";
214 m_levelMap[kFATAL] = "FATAL";
215 m_levelMap[kALWAYS] = "ALWAYS";
216
217 m_colorMap[kVERBOSE] = "\033[1;34m";
218 m_colorMap[kDEBUG] = "\033[34m";
219 m_colorMap[kINFO] = "";
220 m_colorMap[kWARNING] = "\033[1;31m";
221 m_colorMap[kERROR] = "\033[1;31m";
222 m_colorMap[kFATAL] = "\033[37;41;1m";
223 m_colorMap[kALWAYS] = "\033[30m";
224}
std::map< TMsgLevel, std::string > m_colorMap
Definition TMsgLogger.h:114
@ kALWAYS
Definition TMsgLogger.h:44
@ kERROR
Definition TMsgLogger.h:42
@ kWARNING
Definition TMsgLogger.h:41
@ kDEBUG
Definition TMsgLogger.h:39
@ kFATAL
Definition TMsgLogger.h:43
@ kVERBOSE
Definition TMsgLogger.h:38

◆ MapLevel()

Root::TMsgLevel Root::TMsgLogger::MapLevel ( const TString & instr) const

Definition at line 190 of file TMsgLogger.cxx.

191{
192 TString ins = instr; // need to copy
193 ins.ToUpper();
194
195 // find the corresponding key
196 std::map<TMsgLevel, std::string>::const_iterator it = m_levelMap.begin();
197 for (; it != m_levelMap.end(); ++it) if (ins == it->second) return it->first;
198
199 // not found --> fatal error
200 TString line( Form( "fatal error in <TMsgLogger::MapLevel> unknown output level: %s ==> abort", ins.Data() ) );
201 cout << m_colorMap.find( kFATAL )->second << m_prefix << line << "\033[0m" << endl;
202 abort();
203
204 return kFATAL;
205}

◆ operator<<() [1/5]

TMsgLogger & Root::TMsgLogger::operator<< ( std::ios &(* _f )(std::ios &))
inline

Definition at line 131 of file TMsgLogger.h.

132 {
133 (_f)(*this);
134 return *this;
135 }

◆ operator<<() [2/5]

TMsgLogger & Root::TMsgLogger::operator<< ( std::ostream &(* _f )(std::ostream &))
inline

Definition at line 125 of file TMsgLogger.h.

126 {
127 (_f)(*this);
128 return *this;
129 }

◆ operator<<() [3/5]

template<class T>
TMsgLogger & Root::TMsgLogger::operator<< ( T arg)
inline

Definition at line 87 of file TMsgLogger.h.

87 {
88 *static_cast<std::ostringstream*>(this) << arg;
89 return *this;
90 }

◆ operator<<() [4/5]

TMsgLogger & Root::TMsgLogger::operator<< ( TMsgLevel level)
inline

Definition at line 137 of file TMsgLogger.h.

138 {
140 return *this;
141 }

◆ operator<<() [5/5]

TMsgLogger & Root::TMsgLogger::operator<< ( TMsgLogger &(* _f )(TMsgLogger &))
inline

Definition at line 120 of file TMsgLogger.h.

121 {
122 return (_f)(*this);
123 }

◆ operator=()

Root::TMsgLogger & Root::TMsgLogger::operator= ( const TMsgLogger & parent)

Definition at line 93 of file TMsgLogger.cxx.

94{
95 if (this != &parent) {
96 m_objSource = parent.m_objSource;
97 m_strSource = parent.m_strSource;
98 m_activeLevel = parent.m_activeLevel;
99 }
100
101 return *this;
102}

◆ Send()

void Root::TMsgLogger::Send ( )
private

Definition at line 129 of file TMsgLogger.cxx.

130{
131 // activates the logger writer
132
133 // make sure the source name is no longer than m_maxSourceSize:
134 string source_name = GetFormattedSource();
135
136 string message = this->str();
137 string::size_type previous_pos = 0, current_pos = 0;
138
139 // slice the message into lines:
140 for (;;) {
141 current_pos = message.find( '\n', previous_pos );
142 string line = message.substr( previous_pos, current_pos - previous_pos );
143
144 ostringstream message_to_send;
145 // must call the modifiers like this, otherwise g++ get's confused with the operators...
146 message_to_send.setf( ios::adjustfield, ios::left );
147 message_to_send.width( m_maxSourceSize );
148 message_to_send << source_name << m_suffix << line;
149 this->WriteMsg( m_activeLevel, message_to_send.str() );
150
151 if (current_pos == message.npos) break;
152 previous_pos = current_pos + 1;
153 }
154
155 // reset the stream buffer:
156 this->str( "" );
157 return;
158}
void WriteMsg(TMsgLevel level, const std::string &line) const

◆ SetMinLevel()

void Root::TMsgLogger::SetMinLevel ( TMsgLevel minLevel)
inlinestatic

Definition at line 92 of file TMsgLogger.h.

92{ m_minLevel = minLevel; }

◆ SetSource() [1/3]

void Root::TMsgLogger::SetSource ( const char * source)
inline

Definition at line 58 of file TMsgLogger.h.

◆ SetSource() [2/3]

void Root::TMsgLogger::SetSource ( const std::string & source)
inline

Definition at line 59 of file TMsgLogger.h.

◆ SetSource() [3/3]

void Root::TMsgLogger::SetSource ( const TString & source)
inline

Definition at line 60 of file TMsgLogger.h.

60{ m_strSource = source.Data(); }

◆ WriteMsg()

void Root::TMsgLogger::WriteMsg ( TMsgLevel level,
const std::string & line ) const
private

Definition at line 160 of file TMsgLogger.cxx.

161{
162 if (mlevel < GetMinLevel()) return;
163 map<TMsgLevel, std::string>::const_iterator slevel;
164 if ((slevel = m_levelMap.find( mlevel )) == m_levelMap.end()) return;
165#ifdef USE_COLORED_CONSOLE
166 // no text for INFO
167 if (mlevel == kINFO)
168 cout << m_colorMap.find( mlevel )->second << m_prefix << line << "\033[0m" << endl;
169 else
170 cout << m_colorMap.find( mlevel )->second << m_prefix
171 << "<" << slevel->second << "> " << line << "\033[0m" << endl;
172#else
173 if (mlevel == kINFO)
174 cout << m_prefix << line << endl;
175 else
176 cout << m_prefix << "<" << slevel->second << "> " << line << endl;
177#endif // USE_COLORED_CONSOLE
178
179 // take decision to stop if fatal error
180 if (mlevel == kFATAL) { cout << "***> abort program execution" << endl; std::abort(); }
181}
TMsgLevel GetMinLevel() const
Definition TMsgLogger.h:67

Member Data Documentation

◆ m_activeLevel

TMsgLevel Root::TMsgLogger::m_activeLevel
private

Definition at line 110 of file TMsgLogger.h.

◆ m_colorMap

std::map<TMsgLevel, std::string> Root::TMsgLogger::m_colorMap
private

Definition at line 114 of file TMsgLogger.h.

◆ m_levelMap

std::map<TMsgLevel, std::string> Root::TMsgLogger::m_levelMap
private

Definition at line 113 of file TMsgLogger.h.

◆ m_maxSourceSize

const std::string::size_type Root::TMsgLogger::m_maxSourceSize
private

Definition at line 111 of file TMsgLogger.h.

◆ m_minLevel

std::atomic< Root::TMsgLevel > Root::TMsgLogger::m_minLevel = kINFO
staticprivate

Definition at line 99 of file TMsgLogger.h.

◆ m_objSource

const TObject* Root::TMsgLogger::m_objSource
private

Definition at line 106 of file TMsgLogger.h.

◆ m_prefix

const std::string Root::TMsgLogger::m_prefix
private

Definition at line 108 of file TMsgLogger.h.

◆ m_strSource

std::string Root::TMsgLogger::m_strSource
private

Definition at line 107 of file TMsgLogger.h.

◆ m_suffix

const std::string Root::TMsgLogger::m_suffix
private

Definition at line 109 of file TMsgLogger.h.


The documentation for this class was generated from the following files: