47 #ifndef _MIRA_LOGGINGCORE_H_ 48 #define _MIRA_LOGGINGCORE_H_ 53 #include <boost/thread/mutex.hpp> 54 #include <boost/function.hpp> 116 std::string
function;
136 template<
typename Reflector>
139 r.member(
"level", record.
level,
"Log level");
140 r.member(
"time", record.
time,
"Log time");
141 r.member(
"uptime", record.
uptime,
"Log uptime");
142 r.member(
"message", record.
message,
"Log message");
143 r.member(
"line", record.
line,
"Line in file where log call occurred");
144 r.member(
"file", record.
file,
"File where log call occurred");
145 r.member(
"function", record.
function,
"Function where log call occurred");
146 r.member(
"threadID", record.
threadID,
"ID of thread where log call occurred");
219 void aboutToConsume(
const LogRecord& record);
226 virtual void consume(
const LogRecord& record) = 0;
242 template <
typename T>
245 mFilter.reset(
new T(filter));
263 template <
typename T>
266 mFormatter.reset(
new T(formatter));
311 boost::mutex::scoped_lock lock(mCallbackMutex);
312 mSeverityLevel = level;
313 foreach(
auto i, mSeverityChangedCallbacks)
323 return mSeverityLevel;
333 boost::mutex::scoped_lock lock(mCallbackMutex);
334 mSeverityChangedCallbacks[mCallbackCounter] = callback;
335 return mCallbackCounter++;
343 boost::mutex::scoped_lock lock(mCallbackMutex);
344 mSeverityChangedCallbacks.erase(
id);
362 template <
typename T>
365 boost::mutex::scoped_lock lock(mSinkMutex);
367 mSinks.push_back(ptr);
377 boost::mutex::scoped_lock lock(mSinkMutex);
378 auto i = mSinks.begin();
379 for (; i!= mSinks.end(); ++i)
382 if (i != mSinks.end())
394 boost::mutex::scoped_lock lock(mSinkMutex);
395 record.
uptime = getUptime();
396 for(
size_t i=0; i<mSinks.size(); ++i)
397 mSinks[i]->aboutToConsume(record);
401 boost::mutex mSinkMutex;
402 boost::mutex mCallbackMutex;
405 std::vector<LogSinkPtr> mSinks;
406 uint32 mCallbackCounter;
407 std::map<uint32, SeverityLevelChangedCallback> mSeverityChangedCallbacks;
417 #define MIRA_LOGGER (mira::LogCore::instance()) 435 const std::string&
file,
int line,
436 const std::string&
function,
ThreadID threadID)
480 #ifndef MIRA_SEVERITY_MAX_LEVEL 482 # define MIRA_SEVERITY_MAX_LEVEL mira::NOTICE 484 # define MIRA_SEVERITY_MAX_LEVEL mira::TRACE 529 #define MIRA_LOG(level) \ 530 if (level > MIRA_SEVERITY_MAX_LEVEL) {} \ 531 else if (constexpr auto fileInMIRAPath = mira::chopMIRAPath(__FILE__); level > MIRA_LOGGER.getSeverityLevel()) {} \ 532 else mira::Logger(level, mira::Time::now(), fileInMIRAPath, __LINE__, MIRA_FUNCTION, mira::getCurrentThreadID()).stream() 542 #define MIRA_LOG_ALWAYS(level) \ 543 if constexpr (constexpr auto fileInMIRAPath = mira::chopMIRAPath(__FILE__); true) \ 544 mira::Logger(level, mira::Time::now(), fileInMIRAPath, __LINE__, MIRA_FUNCTION, mira::getCurrentThreadID()).stream() 550 #define MIRA_LOG_ATTR(level, time, file, line, function, threadID) \ 551 if (level > MIRA_SEVERITY_MAX_LEVEL) {} \ 552 else if (constexpr auto fileInMIRAPath = mira::chopMIRAPath(__FILE__); level > MIRA_LOGGER.getSeverityLevel()) {} \ 553 else mira::Logger(level, time, file, line, function, threadID).stream() 555 #define MIRA_TRACE MIRA_LOG(mira::TRACE) << "in : " << fileInMIRAPath << "(" << __LINE__ << ") in " << MIRA_FUNCTION << " " Macro for iterating over all elements in a container.
SeverityLevel level
Definition: LoggingCore.h:109
LogFilterPtr mFilter
Definition: LoggingCore.h:272
Typedefs for OS independent basic data types.
boost::function< void(SeverityLevel)> SeverityLevelChangedCallback
Signature of a callback function for log severity level changes.
Definition: LoggingCore.h:291
Single instance of the core logging class.
Definition: LoggingCore.h:286
Holds all the information about a log entry.
Definition: LoggingCore.h:107
Duration uptime
Definition: LoggingCore.h:111
void unregisterSink(LogSinkPtr sink)
Unregisters a sink.
Definition: LoggingCore.h:375
LogSinkPtr registerSink(const T &sink)
Register a new sink.
Definition: LoggingCore.h:363
std::string function
Definition: LoggingCore.h:116
~Logger()
Destructor.
Definition: LoggingCore.h:447
PropertyHint file(const std::string &filters=std::string(), bool save=false)
Tells the property editor that the path is for a file, and that it should show a "File Open"/"File Sa...
Definition: Path.h:247
Duration getUptime() const
Get the up-time of the core.
Definition: LoggingCore.h:351
Abstract base class for log filters.
Definition: LoggingCore.h:183
boost::shared_ptr< LogSink > LogSinkPtr
A shared pointer for a log sink.
Definition: LoggingCore.h:276
Holds information about a log entry function.
Definition: LoggingCore.h:125
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
Compile-time path handling.
void resetFilter()
Resets the log filter.
Definition: LoggingCore.h:232
std::string nameSpace
Definition: LoggingCore.h:127
Time and Duration wrapper class.
Helper class that is created to make one logging process atomic and thread safe.
Definition: LoggingCore.h:427
uint32 ThreadID
Platform independent thread ID.
Definition: ThreadID.h:68
Definition: LoggingCore.h:79
Provided for convenience.
Definition: Singleton.h:564
SeverityLevel
Severity levels to graduate between different log outputs.
Definition: LoggingCore.h:72
Logger(SeverityLevel level, const Time &time, const std::string &file, int line, const std::string &function, ThreadID threadID)
The constructor taking the details of a log entry.
Definition: LoggingCore.h:433
LogFormatterPtr setFormatter(const T &formatter)
Set the formatter.
Definition: LoggingCore.h:264
std::ostringstream mStream
Definition: LoggingCore.h:465
void unregisterCallback(uint32 id)
Unregister a callback function.
Definition: LoggingCore.h:341
Wrapper class for boost::posix_time::ptime for adding more functionality to it.
Definition: Time.h:418
OS independent thread id.
int line
Definition: LoggingCore.h:114
std::string file
Definition: LoggingCore.h:115
LogFilterPtr setFilter(const T &filter)
Set the filter.
Definition: LoggingCore.h:243
boost::shared_ptr< LogFormatterBase > LogFormatterPtr
A shared pointer for a log formatter.
Definition: LoggingCore.h:171
A singleton class that can be freely configured using policies that control the creation, instantiation, lifetime and thread-safety.
Use this class to represent time durations.
Definition: Time.h:106
uint32 registerCallback(SeverityLevelChangedCallback callback)
Register a callback function.
Definition: LoggingCore.h:331
void resetFormatter()
Resets the formatter.
Definition: LoggingCore.h:253
std::string message
Definition: LoggingCore.h:112
void reflect(Reflector &r, LogRecord &record)
Non-intrusive reflector for LogRecord.
Definition: LoggingCore.h:137
void setSeverityLevel(SeverityLevel level)
Sets the application wide severity level.
Definition: LoggingCore.h:309
void log(LogRecord &record)
Writes a log record and distribute it between all the registered sinks.
Definition: LoggingCore.h:392
std::string className
Definition: LoggingCore.h:128
virtual ~LogFilterBase()
Destructor.
Definition: LoggingCore.h:188
boost::shared_ptr< LogFilterBase > LogFilterPtr
A shared pointer for a log filter.
Definition: LoggingCore.h:199
ThreadID threadID
Definition: LoggingCore.h:117
const std::string severityLevelStr[]
String conversion for the enum severity types.
Definition: LoggingCore.h:85
Time time
Definition: LoggingCore.h:110
Abstract base class for all log sinks.
Definition: LoggingCore.h:208
Definition: LoggingCore.h:76
static Time now() static Time eternity()
Returns the current utc based time.
Definition: Time.h:481
MIRA_BASE_EXPORT SeverityLevel stringToSeverityLevel(const std::string &levelString)
Converts the specified string into a numeric severity level.
Definition: LoggingCore.h:74
virtual bool filter(const LogRecord &record)=0
Filters a log entry.
Definition: LoggingCore.h:78
std::string functionName
Definition: LoggingCore.h:129
Definition: LoggingCore.h:75
SeverityLevel getSeverityLevel() const
Get the application wide severity level.
Definition: LoggingCore.h:321
LogRecord mRecord
Definition: LoggingCore.h:464
virtual ~LogSink()
Destructor.
Definition: LoggingCore.h:213
std::string details
Definition: LoggingCore.h:113
LogFormatterPtr mFormatter
Definition: LoggingCore.h:271
Definition: LoggingCore.h:77
#define MIRA_LOGGER
Macro for easier access to the logging core instance.
Definition: LoggingCore.h:417
std::ostringstream & stream()
Get the underlying stream.
Definition: LoggingCore.h:457