60#if __cplusplus > 199711L
69static std::unique_ptr<const std::map<TMVA::EMsgType, std::string> >
gOwnTypeMap;
70static std::unique_ptr<const std::map<TMVA::EMsgType, std::string> >
gOwnColorMap;
79 : fObjSource ( source ),
92 fStrSource ( source ),
104 fStrSource (
"Unknown" ),
105 fActiveType( kINFO ),
116 std::ostringstream(),
136 if (&parent !=
this) {
151 std::string source_name;
152 if (fActiveType == kHEADER)
154 source_name = fStrSource;
156 if (fActiveType == kWARNING)
158 source_name =
"<WARNING>";
160 if (source_name.size() > fgMaxSourceSize) {
161 source_name = source_name.substr( 0, fgMaxSourceSize - 3 );
162 source_name +=
"...";
173 return static_cast<UInt_t>(fgMaxSourceSize);
181 std::string source_name = GetFormattedSource();
182 if (source_name.size() < fgMaxSourceSize)
183 for (std::string::size_type i=source_name.size(); i<fgMaxSourceSize; i++) source_name.push_back(
' ' );
185 return fgPrefix + source_name + fgSuffix;
194 std::string source_name = GetFormattedSource();
196 std::string message = this->str();
197 std::string::size_type previous_pos = 0, current_pos = 0;
201 current_pos = message.find(
'\n', previous_pos );
202 std::string
line = message.substr( previous_pos, current_pos - previous_pos );
204 std::ostringstream message_to_send;
206 message_to_send.setf( std::ios::adjustfield, std::ios::left );
207 message_to_send.width( fgMaxSourceSize );
208 message_to_send << source_name << fgSuffix <<
line;
209 std::string msg = message_to_send.str();
210 this->WriteMsg( fActiveType, msg );
212 if (current_pos == message.npos)
break;
213 previous_pos = current_pos + 1;
228 if ( (
type < fMinType || fgInhibitOutput) &&
type!=kFATAL )
return;
230 std::map<EMsgType, std::string>::const_iterator stype;
232 if ((stype = fgTypeMap.load()->find(
type )) != fgTypeMap.load()->end()) {
236 if (
type == kHEADER ||
type ==kWARNING)
237 std::cout << fgPrefix <<
line << std::endl;
238 else if (
type == kINFO ||
type == kVERBOSE)
240 std::cout <<
line << std::endl;
243 std::cout << fgColorMap.load()->find(
type )->second <<
"<" << stype->second <<
">" <<
line <<
"\033[0m" << std::endl;
248 if (
type == kINFO) std::cout << fgPrefix <<
line << std::endl;
249 else std::cout << fgPrefix <<
"<" << stype->second <<
"> " <<
line << std::endl;
255 if (
type == kFATAL) {
256 std::cout <<
"***> abort program execution" << std::endl;
257 throw std::runtime_error(
"FATAL error");
279 std::map<TMVA::EMsgType, std::string>*tmp =
new std::map<TMVA::EMsgType, std::string>();
281 (*tmp)[kVERBOSE] = std::string(
"VERBOSE");
282 (*tmp)[kDEBUG] = std::string(
"DEBUG");
283 (*tmp)[kINFO] = std::string(
"INFO");
284 (*tmp)[kWARNING] = std::string(
"WARNING");
285 (*tmp)[kERROR] = std::string(
"ERROR");
286 (*tmp)[kFATAL] = std::string(
"FATAL");
287 (*tmp)[kSILENT] = std::string(
"SILENT");
288 (*tmp)[kHEADER] = std::string(
"HEADER");
289 const std::map<TMVA::EMsgType, std::string>* expected=0;
290 if(fgTypeMap.compare_exchange_strong(expected,tmp)) {
300 std::map<TMVA::EMsgType, std::string>*tmp =
new std::map<TMVA::EMsgType, std::string>();
302 (*tmp)[kVERBOSE] = std::string(
"");
303 (*tmp)[kDEBUG] = std::string(
"\033[34m");
304 (*tmp)[kINFO] = std::string(
"");
305 (*tmp)[kWARNING] = std::string(
"\033[1;31m");
306 (*tmp)[kERROR] = std::string(
"\033[31m");
307 (*tmp)[kFATAL] = std::string(
"\033[37;41;1m");
308 (*tmp)[kSILENT] = std::string(
"\033[30m");
310 const std::map<TMVA::EMsgType, std::string>* expected=0;
311 if(fgColorMap.compare_exchange_strong(expected,tmp)) {
static std::unique_ptr< const std::map< TMVA::EMsgType, std::string > > gOwnTypeMap
static std::unique_ptr< const std::map< TMVA::EMsgType, std::string > > gOwnColorMap
ostringstream derivative to redirect and format output
static const UInt_t fgMaxSourceSize
static const std::string fgPrefix
MsgLogger(const TObject *source, EMsgType minType=kINFO)
constructor
MsgLogger & operator=(const MsgLogger &parent)
assignment operator
std::string GetPrintedSource() const
the full logger prefix
static UInt_t GetMaxSourceSize()
returns the maximum source size
static void InhibitOutput()
const TObject * fObjSource
static const std::string fgSuffix
static void EnableOutput()
static const std::map< EMsgType, std::string > * fgTypeMap
std::string GetFormattedSource() const
make sure the source name is no longer than fgMaxSourceSize:
static Bool_t fgInhibitOutput
void InitMaps()
Create the message type and color maps.
void WriteMsg(EMsgType type, const std::string &line) const
putting the output string, the message type, and the color switcher together into a single string
static MsgLogger & Endmsg(MsgLogger &logger)
end line
static const std::map< EMsgType, std::string > * fgColorMap
void Send()
activates the logger writer
Mother of all ROOT objects.