ATLAS Offline Software
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
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 52 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 ),
47  m_activeLevel( kINFO ),
48  m_maxSourceSize( MAXIMUM_SOURCE_NAME_LENGTH )
49 {
50  // constructor
51  InitMaps();
52 }

◆ 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 ),
59  m_activeLevel( kINFO ),
60  m_maxSourceSize( MAXIMUM_SOURCE_NAME_LENGTH )
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 ),
71  m_activeLevel( kINFO ),
72  m_maxSourceSize( MAXIMUM_SOURCE_NAME_LENGTH )
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 ),
83  m_suffix( SUFFIX ),
84  m_maxSourceSize( MAXIMUM_SOURCE_NAME_LENGTH )
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 }

◆ 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 68 of file TMsgLogger.h.

68 { return m_levelMap.find( m_minLevel )->second; }

◆ GetMinLevel()

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

Definition at line 72 of file TMsgLogger.h.

◆ GetMinLevelStr()

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

Definition at line 73 of file TMsgLogger.h.

◆ 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 }

◆ GetSource()

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

Definition at line 66 of file TMsgLogger.h.

67 { return m_minLevel; }

◆ 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 }

◆ 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 &(*)(std::ios &)  _f)
inline

Definition at line 135 of file TMsgLogger.h.

137  {
139  return *this;

◆ operator<<() [2/5]

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

Definition at line 129 of file TMsgLogger.h.

131  {
132  (_f)(*this);
133  return *this;

◆ operator<<() [3/5]

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

Definition at line 92 of file TMsgLogger.h.

93  :
94 

◆ operator<<() [4/5]

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

Definition at line 141 of file TMsgLogger.h.

◆ operator<<() [5/5]

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

Definition at line 124 of file TMsgLogger.h.

125  {
126  (_f)(*this);
127  return *this;

◆ 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 }

◆ SetMinLevel()

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

Definition at line 96 of file TMsgLogger.h.

◆ SetSource() [1/3]

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

Definition at line 63 of file TMsgLogger.h.

63 { return (UInt_t)m_maxSourceSize; }

◆ SetSource() [2/3]

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

Definition at line 64 of file TMsgLogger.h.

◆ SetSource() [3/3]

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

Definition at line 65 of file TMsgLogger.h.

67 { return m_minLevel; }

◆ 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 }

Member Data Documentation

◆ m_activeLevel

TMsgLevel Root::TMsgLogger::m_activeLevel
private

Definition at line 114 of file TMsgLogger.h.

◆ m_colorMap

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

Definition at line 118 of file TMsgLogger.h.

◆ m_levelMap

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

Definition at line 117 of file TMsgLogger.h.

◆ m_maxSourceSize

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

Definition at line 115 of file TMsgLogger.h.

◆ m_minLevel

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

Definition at line 103 of file TMsgLogger.h.

◆ m_objSource

const TObject* Root::TMsgLogger::m_objSource
private

Definition at line 110 of file TMsgLogger.h.

◆ m_prefix

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

Definition at line 112 of file TMsgLogger.h.

◆ m_strSource

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

Definition at line 111 of file TMsgLogger.h.

◆ m_suffix

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

Definition at line 113 of file TMsgLogger.h.


The documentation for this class was generated from the following files:
Root::TMsgLogger::m_suffix
const std::string m_suffix
Definition: TMsgLogger.h:113
Root::TMsgLogger::WriteMsg
void WriteMsg(TMsgLevel level, const std::string &line) const
Definition: TMsgLogger.cxx:160
Root::kWARNING
@ kWARNING
Definition: TMsgLogger.h:51
checkFileSG.line
line
Definition: checkFileSG.py:75
Root::TMsgLogger::m_objSource
const TObject * m_objSource
Definition: TMsgLogger.h:110
skel.it
it
Definition: skel.GENtoEVGEN.py:423
Root::kERROR
@ kERROR
Definition: TMsgLogger.h:52
Root::TMsgLogger::GetMinLevel
TMsgLevel GetMinLevel() const
Definition: TMsgLogger.h:72
Root::kVERBOSE
@ kVERBOSE
Definition: TMsgLogger.h:48
ReweightUtils.message
message
Definition: ReweightUtils.py:15
Root::kALWAYS
@ kALWAYS
Definition: TMsgLogger.h:54
python.iconfTool.models.loaders.level
level
Definition: loaders.py:20
Root::TMsgLogger::m_prefix
const std::string m_prefix
Definition: TMsgLogger.h:112
Root::TMsgLogger::GetFormattedSource
std::string GetFormattedSource() const
Definition: TMsgLogger.cxx:104
Root::kDEBUG
@ kDEBUG
Definition: TMsgLogger.h:49
lumiFormat.i
int i
Definition: lumiFormat.py:92
Root::kINFO
@ kINFO
Definition: TMsgLogger.h:50
Root::TMsgLogger::m_strSource
std::string m_strSource
Definition: TMsgLogger.h:111
test_pyathena.parent
parent
Definition: test_pyathena.py:15
Root::TMsgLogger::m_minLevel
static std::atomic< TMsgLevel > m_minLevel
Definition: TMsgLogger.h:103
python.CaloScaleNoiseConfig.str
str
Definition: CaloScaleNoiseConfig.py:78
Root::TMsgLogger::m_maxSourceSize
const std::string::size_type m_maxSourceSize
Definition: TMsgLogger.h:115
Root::TMsgLogger::InitMaps
void InitMaps()
Definition: TMsgLogger.cxx:207
Root::TMsgLogger::m_activeLevel
TMsgLevel m_activeLevel
Definition: TMsgLogger.h:114
Root::TMsgLogger::m_colorMap
std::map< TMsgLevel, std::string > m_colorMap
Definition: TMsgLogger.h:118
Root::TMsgLogger::m_levelMap
std::map< TMsgLevel, std::string > m_levelMap
Definition: TMsgLogger.h:117
Root::kFATAL
@ kFATAL
Definition: TMsgLogger.h:53
python.iconfTool.gui.pad.logger
logger
Definition: pad.py:14