trick/trick_source/sim_services/Message/MessageCout.cpp
Michael Vetter 18f0d7e871 Remove trailing whitespaces
Makes it easier to edit the files. So if we press 'end of line' we are
really at the end of line.
2016-11-08 10:25:07 +01:00

55 lines
1.5 KiB
C++

#include "trick/MessageCout.hh"
#include "trick/message_type.h"
#include <sstream>
Trick::MessageCout::MessageCout() {
/** By default, this subscriber is enabled when it is created. */
enabled = 1 ;
color = 1 ;
name = "cout" ;
}
void Trick::MessageCout::update( unsigned int level , std::string header , std::string message ) {
/** @par Design Details: */
std::string color_code ;
switch (level) {
case MSG_NORMAL :
color_code = "\033[00m" ; // normal
break ;
case MSG_INFO :
color_code = "\033[32m" ; // green
break ;
case MSG_WARNING :
color_code = "\033[33m" ; // yellow
break ;
case MSG_ERROR :
color_code = "\033[31m" ; // red
break ;
case MSG_DEBUG :
color_code = "\033[36m" ; // cyan
break ;
default :
color_code = "\033[00m" ; // normal
break ;
}
/** @li Prints the received message to the standard output stream. */
if (enabled && level < 100 ) {
// Building the final string in a temporary stream ensures an automic call to cout, which prevents
// multithreaded sims from interleaving header and message elements.
std::ostringstream oss;
if ( color ) {
oss << header << color_code << message << "\033[00m" ;
} else {
oss << header << message ;
}
std::cout << oss.str() << std::flush;
}
}