2015-02-26 15:02:31 +00:00
|
|
|
|
2015-06-01 15:28:29 +00:00
|
|
|
#include "trick/MessageCout.hh"
|
|
|
|
#include "trick/message_type.h"
|
2015-02-26 15:02:31 +00:00
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
Trick::MessageCout::MessageCout() {
|
|
|
|
/** By default, this subscriber is enabled when it is created. */
|
|
|
|
enabled = 1 ;
|
|
|
|
color = 1 ;
|
|
|
|
name = "cout" ;
|
|
|
|
}
|
|
|
|
|
2016-11-08 09:25:07 +00:00
|
|
|
void Trick::MessageCout::update( unsigned int level , std::string header , std::string message ) {
|
2015-02-26 15:02:31 +00:00
|
|
|
|
|
|
|
/** @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 ) {
|
2016-11-08 09:25:07 +00:00
|
|
|
|
2015-02-26 15:02:31 +00:00
|
|
|
// 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;
|
|
|
|
}
|
2016-11-08 09:25:07 +00:00
|
|
|
}
|
2015-02-26 15:02:31 +00:00
|
|
|
|