21 #ifndef GRT_LOG_HEADER 22 #define GRT_LOG_HEADER 24 #include "GRTTypedefs.h" 26 #ifdef GRT_CXX11_ENABLED 30 #endif //GRT_CXX11_ENABLED 39 typedef std::basic_ostream<char, std::char_traits<char> >
CoutType;
40 typedef CoutType& (*StandardEndLine)(CoutType&);
46 Log(
const std::string &key =
""){
48 instanceLoggingEnabled =
true;
50 loggingEnabledPtr = &instanceLoggingEnabled;
51 writeKeyPtr = &writeKey;
52 lastMessagePtr = &lastMessage;
64 this->loggingEnabledPtr = &(this->instanceLoggingEnabled);
65 this->writeKeyPtr = &(this->writeKey);
66 this->lastMessagePtr = &(this->lastMessage);
82 this->loggingEnabledPtr = &(this->instanceLoggingEnabled);
83 this->writeKeyPtr = &(this->writeKey);
84 this->lastMessagePtr = &(this->lastMessage);
93 const Log& operator<< (
const T &val )
const{
95 #ifdef GRT_CXX11_ENABLED 96 std::unique_lock<std::mutex> lock( logMutex );
98 if( !baseLoggingEnabled )
return *
this;
100 if( *loggingEnabledPtr && instanceLoggingEnabled ){
102 *writeKeyPtr =
false;
103 std::cout << key.c_str();
105 *lastMessagePtr =
"";
108 std::stringstream stream;
110 *lastMessagePtr += stream.str();
120 #ifdef GRT_CXX11_ENABLED 121 std::unique_lock<std::mutex> lock( logMutex );
123 if( !baseLoggingEnabled )
return *
this;
125 if( *loggingEnabledPtr && instanceLoggingEnabled ){
131 triggerCallback( lastMessage );
142 return instanceLoggingEnabled;
166 virtual bool setKey(
const std::string &key){
167 if( key.length() == 0 ) this->key =
"";
168 else this->key = key;
177 return baseLoggingEnabled;
185 return this->instanceLoggingEnabled;
193 baseLoggingEnabled = enabled;
202 this->instanceLoggingEnabled = loggingEnabled;
206 GRT_DEPRECATED_MSG(
"setProceedingText is deprecated, use setKey instead",
void setProceedingText(std::string proceedingText) );
207 GRT_DEPRECATED_MSG(
"getProceedingText is deprecated, use getKey instead", std::string getProceedingText()
const );
208 GRT_DEPRECATED_MSG(
"setEnableInstanceLogging is deprecated, use setInstanceLoggingEnabled instead",
bool setEnableInstanceLogging(
const bool loggingEnabled) );
230 #ifdef GRT_CXX11_ENABLED 231 static std::mutex logMutex;
237 #endif //GRT_LOG_HEADER static bool setLoggingEnabled(const bool enabled)
sets if logging is enabled for this class, this supersedes the specific instance logging ...
std::basic_ostream< char, std::char_traits< char > > CoutType
this is the type of std::cout
std::string key
The key that will be written at the start of each log.
std::string * lastMessagePtr
This is a hack that enables variables to be updated inside const methods.
static bool baseLoggingEnabled
This controls logging across all Log instances, as opposed to a single instance.
std::string lastMessage
The last message written.
virtual std::string getLastMessage() const
returns the last message written by the log
virtual bool setKey(const std::string &key)
sets the key that gets written at the start of each message, this will be written in the format 'key ...
virtual void triggerCallback(const std::string &message) const
This callback can be used to propagate messages to other interfaces (e.g., a GUI built on top of the ...
Log(const std::string &key="")
defines the log default constructor
virtual bool setInstanceLoggingEnabled(const bool loggingEnabled)
sets if logging is enabled for this specific instance
virtual bool getInstanceLoggingEnabled() const
returns true if logging is enabled for this specific instance
virtual bool getInstanceLoggingEnabled()
returns if logging is enabled for this specific instance
virtual std::string getKey() const
returns the key that gets written at the start of each message
bool * loggingEnabledPtr
This is a hack that enables variables to be updated inside const methods.
Log(const Log &rhs)
defines the log copy constructor
The Log class provides the base class for all GRT logging functionality.
Log & operator=(const Log &rhs)
defines the log equals operator
const Log & operator<<(const StandardEndLine manip) const
defines an operator<< to take in std::endl, this ends a message and triggers the mesaage callback ...
static bool getLoggingEnabled()
returns true if logging is enabled for this class, this supersedes the specific instance logging ...
bool writeKey
If true, then the key will be written at the start of each log message.
bool * writeKeyPtr
This is a hack that enables variables to be updated inside const methods.
bool instanceLoggingEnabled
If true, then this instance should log messages.