21 #ifndef GRT_LOG_HEADER
22 #define GRT_LOG_HEADER
24 #include "GRTTypedefs.h"
26 #ifdef GRT_CXX11_ENABLED
30 #endif //GRT_CXX11_ENABLED
36 Log(std::string proceedingText =
""){
37 setProceedingText(proceedingText);
38 loggingEnabledPtr = NULL;
39 instanceLoggingEnabled =
true;
40 writeProceedingText =
true;
41 writeProceedingTextPtr = &writeProceedingText;
42 lastMessagePtr = &lastMessage;
48 const Log& operator<< (
const T val )
const{
50 #ifdef GRT_CXX11_ENABLED
51 std::unique_lock<std::mutex> lock( logMutex );
54 if( *loggingEnabledPtr && instanceLoggingEnabled ){
55 if( *writeProceedingTextPtr ){
56 *writeProceedingTextPtr =
false;
57 std::cout << proceedingText.c_str();
61 *lastMessagePtr += val;
67 typedef std::basic_ostream<char, std::char_traits<char> > CoutType;
70 typedef CoutType& (*StandardEndLine)(CoutType&);
73 const Log& operator<<(
const StandardEndLine manip)
const{
75 #ifdef GRT_CXX11_ENABLED
76 std::unique_lock<std::mutex> lock( logMutex );
79 if( *loggingEnabledPtr && instanceLoggingEnabled ){
82 *writeProceedingTextPtr =
true;
85 triggerCallback( lastMessage );
92 virtual bool getLoggingEnabled()
const{
return false; }
94 bool getInstanceLoggingEnabled()
const {
return instanceLoggingEnabled; };
96 std::string getProceedingText()
const{
return proceedingText; }
98 virtual std::string getLastMessage()
const{
return lastMessage; }
101 void setProceedingText(
const std::string &proceedingText){
102 if( proceedingText.length() == 0 ) this->proceedingText =
"";
103 else this->proceedingText = proceedingText +
" ";
106 bool setEnableInstanceLogging(
bool loggingEnabled){
107 this->instanceLoggingEnabled = loggingEnabled;
112 virtual void triggerCallback(
const std::string &message )
const{
117 std::string to_str(
const T &val )
const {
123 std::string proceedingText;
124 std::string lastMessage;
125 bool instanceLoggingEnabled;
126 bool *loggingEnabledPtr;
127 bool *writeProceedingTextPtr;
128 std::string *lastMessagePtr;
129 bool writeProceedingText;
131 #ifdef GRT_CXX11_ENABLED
132 static std::mutex logMutex;
138 #endif //GRT_LOG_HEADER