47 #ifndef _MIRA_LOGGINGCORE_H_
48 #define _MIRA_LOGGINGCORE_H_
53 #include <boost/thread/mutex.hpp>
54 #include <boost/function.hpp>
115 std::string
function;
135 template<
typename Reflector>
138 r.member(
"level", record.
level,
"Log level");
139 r.member(
"time", record.
time,
"Log time");
140 r.member(
"uptime", record.
uptime,
"Log uptime");
141 r.member(
"message", record.
message,
"Log message");
142 r.member(
"line", record.
line,
"Line in file where log call occurred");
143 r.member(
"file", record.
file,
"File where log call occurred");
144 r.member(
"function", record.
function,
"Function where log call occurred");
145 r.member(
"threadID", record.
threadID,
"ID of thread where log call occurred");
218 void aboutToConsume(
const LogRecord& record);
225 virtual void consume(
const LogRecord& record) = 0;
241 template <
typename T>
244 mFilter.reset(
new T(filter));
262 template <
typename T>
265 mFormatter.reset(
new T(formatter));
310 boost::mutex::scoped_lock lock(mCallbackMutex);
311 mSeverityLevel = level;
312 foreach(
auto i, mSeverityChangedCallbacks)
322 return mSeverityLevel;
332 boost::mutex::scoped_lock lock(mCallbackMutex);
333 mSeverityChangedCallbacks[mCallbackCounter] = callback;
334 return mCallbackCounter++;
342 boost::mutex::scoped_lock lock(mCallbackMutex);
343 mSeverityChangedCallbacks.erase(
id);
361 template <
typename T>
364 boost::mutex::scoped_lock lock(mSinkMutex);
366 mSinks.push_back(ptr);
376 boost::mutex::scoped_lock lock(mSinkMutex);
377 auto i = mSinks.begin();
378 for (; i!= mSinks.end(); ++i)
381 if (i != mSinks.end())
393 boost::mutex::scoped_lock lock(mSinkMutex);
394 record.
uptime = getUptime();
395 for(
size_t i=0; i<mSinks.size(); ++i)
396 mSinks[i]->aboutToConsume(record);
400 boost::mutex mSinkMutex;
401 boost::mutex mCallbackMutex;
404 std::vector<LogSinkPtr> mSinks;
405 uint32 mCallbackCounter;
406 std::map<uint32, SeverityLevelChangedCallback> mSeverityChangedCallbacks;
416 #define MIRA_LOGGER (mira::LogCore::instance())
434 const std::string&
file,
int line,
435 const std::string&
function,
ThreadID threadID)
479 #ifndef MIRA_SEVERITY_MAX_LEVEL
481 # define MIRA_SEVERITY_MAX_LEVEL mira::NOTICE
483 # define MIRA_SEVERITY_MAX_LEVEL mira::TRACE
528 #define MIRA_LOG(level) \
529 if (level > MIRA_SEVERITY_MAX_LEVEL) {} \
530 else if (level > MIRA_LOGGER.getSeverityLevel()) {} \
531 else mira::Logger(level, mira::Time::now(), __FILE__, __LINE__, MIRA_FUNCTION, mira::getCurrentThreadID()).stream()
541 #define MIRA_LOG_ALWAYS(level) \
542 mira::Logger(level, mira::Time::now(), __FILE__, __LINE__, MIRA_FUNCTION, mira::getCurrentThreadID()).stream()
548 #define MIRA_LOG_ATTR(level, time, file, line, function, threadID) \
549 if (level > MIRA_SEVERITY_MAX_LEVEL) {} \
550 else if (level > MIRA_LOGGER.getSeverityLevel()) {} \
551 else mira::Logger(level, time, file, line, function, threadID).stream()
553 #define MIRA_TRACE MIRA_LOG(mira::TRACE) << "in : " << __FILE__ << "(" << __LINE__ << ") in " << MIRA_FUNCTION << " "
Macro for iterating over all elements in a container.
SeverityLevel level
Definition: LoggingCore.h:108
LogFilterPtr mFilter
Definition: LoggingCore.h:271
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:290
Single instance of the core logging class.
Definition: LoggingCore.h:285
Holds all the information about a log entry.
Definition: LoggingCore.h:106
Duration uptime
Definition: LoggingCore.h:110
void unregisterSink(LogSinkPtr sink)
Unregisters a sink.
Definition: LoggingCore.h:374
LogSinkPtr registerSink(const T &sink)
Register a new sink.
Definition: LoggingCore.h:362
std::string function
Definition: LoggingCore.h:115
~Logger()
Destructor.
Definition: LoggingCore.h:446
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
Abstract base class for log filters.
Definition: LoggingCore.h:182
boost::shared_ptr< LogSink > LogSinkPtr
A shared pointer for a log sink.
Definition: LoggingCore.h:275
Holds information about a log entry function.
Definition: LoggingCore.h:124
void resetFilter()
Resets the log filter.
Definition: LoggingCore.h:231
std::string nameSpace
Definition: LoggingCore.h:126
Time and Duration wrapper class.
Helper class that is created to make one logging process atomic and thread safe.
Definition: LoggingCore.h:426
uint32 ThreadID
Platform independent thread ID.
Definition: ThreadID.h:68
Definition: LoggingCore.h:78
Provided for convenience.
Definition: Singleton.h:564
SeverityLevel
Severity levels to graduate between different log outputs.
Definition: LoggingCore.h:71
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:432
LogFormatterPtr setFormatter(const T &formatter)
Set the formatter.
Definition: LoggingCore.h:263
std::ostringstream mStream
Definition: LoggingCore.h:464
void unregisterCallback(uint32 id)
Unregister a callback function.
Definition: LoggingCore.h:340
Wrapper class for boost::posix_time::ptime for adding more functionality to it.
Definition: Time.h:421
OS independent thread id.
int line
Definition: LoggingCore.h:113
std::string file
Definition: LoggingCore.h:114
LogFilterPtr setFilter(const T &filter)
Set the filter.
Definition: LoggingCore.h:242
boost::shared_ptr< LogFormatterBase > LogFormatterPtr
A shared pointer for a log formatter.
Definition: LoggingCore.h:170
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:104
uint32 registerCallback(SeverityLevelChangedCallback callback)
Register a callback function.
Definition: LoggingCore.h:330
void resetFormatter()
Resets the formatter.
Definition: LoggingCore.h:252
std::string message
Definition: LoggingCore.h:111
void reflect(Reflector &r, LogRecord &record)
Non-intrusive reflector for LogRecord.
Definition: LoggingCore.h:136
void setSeverityLevel(SeverityLevel level)
Sets the application wide severity level.
Definition: LoggingCore.h:308
void log(LogRecord &record)
Writes a log record and distribute it between all the registered sinks.
Definition: LoggingCore.h:391
std::string className
Definition: LoggingCore.h:127
virtual ~LogFilterBase()
Destructor.
Definition: LoggingCore.h:187
SeverityLevel getSeverityLevel() const
Get the application wide severity level.
Definition: LoggingCore.h:320
boost::shared_ptr< LogFilterBase > LogFilterPtr
A shared pointer for a log filter.
Definition: LoggingCore.h:198
ThreadID threadID
Definition: LoggingCore.h:116
const std::string severityLevelStr[]
String conversion for the enum severity types.
Definition: LoggingCore.h:84
Duration getUptime() const
Get the up-time of the core.
Definition: LoggingCore.h:350
Time time
Definition: LoggingCore.h:109
Abstract base class for all log sinks.
Definition: LoggingCore.h:207
Definition: LoggingCore.h:75
static Time now() static Time eternity()
Returns the current utc based time.
Definition: Time.h:484
MIRA_BASE_EXPORT SeverityLevel stringToSeverityLevel(const std::string &levelString)
Converts the specified string into a numeric severity level.
Definition: LoggingCore.h:73
virtual bool filter(const LogRecord &record)=0
Filters a log entry.
Definition: LoggingCore.h:77
std::string functionName
Definition: LoggingCore.h:128
Definition: LoggingCore.h:74
LogRecord mRecord
Definition: LoggingCore.h:463
virtual ~LogSink()
Destructor.
Definition: LoggingCore.h:212
std::string details
Definition: LoggingCore.h:112
LogFormatterPtr mFormatter
Definition: LoggingCore.h:270
Definition: LoggingCore.h:76
#define MIRA_LOGGER
Macro for easier access to the logging core instance.
Definition: LoggingCore.h:416
std::ostringstream & stream()
Get the underlying stream.
Definition: LoggingCore.h:456