31 #define USE_COLORED_CONSOLE
34 static const string::size_type MAXIMUM_SOURCE_NAME_LENGTH = 20;
36 static const string PREFIX =
"--- ";
38 static const string SUFFIX =
": ";
47 m_activeLevel(
kINFO ),
48 m_maxSourceSize( MAXIMUM_SOURCE_NAME_LENGTH )
59 m_activeLevel(
kINFO ),
60 m_maxSourceSize( MAXIMUM_SOURCE_NAME_LENGTH )
68 m_strSource(
"Unknown" ),
71 m_activeLevel(
kINFO ),
72 m_maxSourceSize( MAXIMUM_SOURCE_NAME_LENGTH )
84 m_maxSourceSize( MAXIMUM_SOURCE_NAME_LENGTH )
96 m_objSource =
parent.m_objSource;
97 m_strSource =
parent.m_strSource;
98 m_activeLevel =
parent.m_activeLevel;
108 if (m_objSource) source_name = m_objSource->GetName();
109 else source_name = m_strSource;
111 if (source_name.size() > m_maxSourceSize) {
112 source_name.resize(m_maxSourceSize - 3 );
113 source_name +=
"...";
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(
' ' );
126 return m_prefix + source_name + m_suffix;
134 string source_name = GetFormattedSource();
137 string::size_type previous_pos = 0, current_pos = 0;
141 current_pos =
message.find(
'\n', previous_pos );
142 string line =
message.substr( previous_pos, current_pos - previous_pos );
144 ostringstream message_to_send;
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() );
151 if (current_pos ==
message.npos)
break;
152 previous_pos = current_pos + 1;
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
168 cout << m_colorMap.find( mlevel )->second << m_prefix <<
line <<
"\033[0m" << endl;
170 cout << m_colorMap.find( mlevel )->second << m_prefix
171 <<
"<" << slevel->second <<
"> " <<
line <<
"\033[0m" << endl;
174 cout << m_prefix <<
line << endl;
176 cout << m_prefix <<
"<" << slevel->second <<
"> " <<
line << endl;
177 #endif // USE_COLORED_CONSOLE
180 if (mlevel ==
kFATAL) { cout <<
"***> abort program execution" << endl; std::abort(); }
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;
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;
210 m_levelMap[
kDEBUG] =
"DEBUG";
211 m_levelMap[
kINFO] =
"INFO";
213 m_levelMap[
kERROR] =
"ERROR";
214 m_levelMap[
kFATAL] =
"FATAL";
215 m_levelMap[
kALWAYS] =
"ALWAYS";
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";