MIRA
Classes | Macros | Enumerations | Functions
Logging Module


For detailed information see Logging More...

Collaboration diagram for Logging Module:

Classes

class  LogConsoleSink
 Special class that uses LogTxtStreamSink as a base and cout as stream Provided for logging to console. More...
 
class  LogCustomizableFilter
 A customizable log filter to match the users needs. More...
 
class  LogCustomizableFormatter
 A customizable formatter. More...
 
class  LogFileSink
 A logging sink for file, which supports log file rotation and daily log files. More...
 
struct  LogRecord
 Holds all the information about a log entry. More...
 
struct  LogRecordFunctionInfo
 Holds information about a log entry function. More...
 
class  LogFormatterBase
 Abstract base class for sink formatters. More...
 
class  LogFilterBase
 Abstract base class for log filters. More...
 
class  LogSink
 Abstract base class for all log sinks. More...
 
class  LogCore
 Single instance of the core logging class. More...
 
class  Logger
 Helper class that is created to make one logging process atomic and thread safe. More...
 
class  LogSimpleFormatter
 Very simple log formatter logging the severity level, the time and the message. More...
 
class  LogTimer
 Class that can be used as a stop watch to measure execution time of operations. More...
 
class  LogTxtStreamSink
 Simple log sink for writing to streams like cout or file It uses the SimpleFormatter for output. More...
 

Macros

#define MIRA_LOG_EXCEPTION(level, ex)
 Log the specified exception, including all information that the exception object carries. More...
 
#define MIRA_LOG_SIGNAL(level, sig)
 Log the error string based on the specified signal and a backtrace if available. More...
 
#define MIRA_LOGGER   (mira::LogCore::instance())
 Macro for easier access to the logging core instance. More...
 
#define MIRA_SEVERITY_MAX_LEVEL   mira::TRACE
 Compile time defined maximum log level In release build the maximum log level should be NOTICE to eliminate some of the logging and gain performance. More...
 
#define MIRA_LOG(level)
 Use this macro to log data. More...
 
#define MIRA_LOG_ALWAYS(level)   mira::Logger(level, mira::Time::now(), __FILE__, __LINE__, MIRA_FUNCTION, mira::getCurrentThreadID()).stream()
 Use this macro to log data. More...
 
#define MIRA_LOG_ATTR(level, time, file, line, function, threadID)
 Use this macro to log data when you have collected the log data yourself. More...
 
#define MIRA_LOGTIMER(level, name, text)
 Macro for starting a LogTimer. More...
 
#define MIRA_PEEKLOGTIMER(name)   name.peek();
 Macro for peeking LogTimer class at a defined point. More...
 
#define MIRA_ENDLOGTIMER(name)   name.end();
 Macro for ending LogTimer class at a defined point. More...
 

Enumerations

enum  SeverityLevel {
  CRITICAL = 0, ERROR = 1, WARNING = 2, NOTICE = 3,
  DEBUG = 4, TRACE = 5
}
 Severity levels to graduate between different log outputs. More...
 

Functions

template<typename Derived1 , typename Derived2 >
LogCustomizableFilter::AndOperator< Derived1, Derived2 > operator & (const LogCustomizableFilter::CustomFilter< Derived1 > &f1, const LogCustomizableFilter::CustomFilter< Derived2 > &f2)
 Operator to combine filters by and. More...
 
template<typename Derived1 , typename Derived2 >
LogCustomizableFilter::OrOperator< Derived1, Derived2 > operator| (const LogCustomizableFilter::CustomFilter< Derived1 > &f1, const LogCustomizableFilter::CustomFilter< Derived2 > &f2)
 Operator to combine filters by or. More...
 
MIRA_BASE_EXPORT SeverityLevel stringToSeverityLevel (const std::string &levelString)
 Converts the specified string into a numeric severity level. More...
 

Detailed Description


For detailed information see Logging

Macro Definition Documentation

◆ MIRA_LOG_EXCEPTION

#define MIRA_LOG_EXCEPTION (   level,
  ex 
)
Value:
if (level > MIRA_SEVERITY_MAX_LEVEL) {} \
else if (level > MIRA_LOGGER.getSeverityLevel()) {} \
else mira::Private::AuxLogger<const std::exception&>(level, ex).stream()
#define MIRA_SEVERITY_MAX_LEVEL
Compile time defined maximum log level In release build the maximum log level should be NOTICE to eli...
Definition: LoggingCore.h:483
#define MIRA_LOGGER
Macro for easier access to the logging core instance.
Definition: LoggingCore.h:416

Log the specified exception, including all information that the exception object carries.

The usage is similar to MIRA_LOG.

◆ MIRA_LOG_SIGNAL

#define MIRA_LOG_SIGNAL (   level,
  sig 
)
Value:
if (level > MIRA_SEVERITY_MAX_LEVEL) {} \
else if (level > MIRA_LOGGER.getSeverityLevel()) {} \
else mira::Private::AuxLogger<const IntSignal&>(level, sig).stream()
#define MIRA_SEVERITY_MAX_LEVEL
Compile time defined maximum log level In release build the maximum log level should be NOTICE to eli...
Definition: LoggingCore.h:483
#define MIRA_LOGGER
Macro for easier access to the logging core instance.
Definition: LoggingCore.h:416

Log the error string based on the specified signal and a backtrace if available.

The usage is similar to MIRA_LOG.

◆ MIRA_LOGGER

#define MIRA_LOGGER   (mira::LogCore::instance())

Macro for easier access to the logging core instance.

◆ MIRA_SEVERITY_MAX_LEVEL

#define MIRA_SEVERITY_MAX_LEVEL   mira::TRACE

Compile time defined maximum log level In release build the maximum log level should be NOTICE to eliminate some of the logging and gain performance.

Effectively, MIRA_SEVERITY_MAX_LEVEL imposes a static plateau on the dynamically allowed range of logging levels: Any logging level above the static plateau is simply eliminated from the code.

◆ MIRA_LOG

#define MIRA_LOG (   level)
Value:
if (level > MIRA_SEVERITY_MAX_LEVEL) {} \
else if (level > MIRA_LOGGER.getSeverityLevel()) {} \
else mira::Logger(level, mira::Time::now(), __FILE__, __LINE__, MIRA_FUNCTION, mira::getCurrentThreadID()).stream()
Helper class that is created to make one logging process atomic and thread safe.
Definition: LoggingCore.h:426
#define MIRA_FUNCTION
Definition: Platform.h:98
static Time now() static Time eternity()
Returns the current utc based time.
Definition: Time.h:484
#define MIRA_SEVERITY_MAX_LEVEL
Compile time defined maximum log level In release build the maximum log level should be NOTICE to eli...
Definition: LoggingCore.h:483
#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

Use this macro to log data.

e.g.

MIRA_LOG(DEBUG) << "Hello, " << "World";

!!!ATTENTION!!! This code combines two tests. If you pass a compile time constant to MIRA_LOG, the first test is against two constants and any optimizer will pick that up statically and discard the dead branch entirely from generated code. The second test examines the runtime logging level. If the specified level is above the runtime logging level the branch will never be called. e.g. Assuming MIRA_SEVERITY_MAX_LEVEL is ERROR:

MIRA_LOG(DEBUG) << callAnImportantFunctionThatNeedsToBeCalledUnderAllCircumstances(42);

will be expanded by the preprocessor to

if (DEBUG > ERROR);
else if ( DEBUG > LogCore::instance()->severityLevel());
else Logger(...).stream() << callAnImportantFunctionThatNeedsToBeCalledUnderAllCircumstances(42);

So the so important function will never be called when the runtime logging level is below the specified.

If you combine a MIRA_LOG with an if case it is strongly recommended to add {} around the MIRA_LOG statement:

if (myCondition)
{
MIRA_LOG(DEBUG) << "My condition is true";
}

Otherwise you will get compiler warnings about an ambiguous else. !!!ATTENTION!!!

◆ MIRA_LOG_ALWAYS

#define MIRA_LOG_ALWAYS (   level)    mira::Logger(level, mira::Time::now(), __FILE__, __LINE__, MIRA_FUNCTION, mira::getCurrentThreadID()).stream()

Use this macro to log data.

In contrast to MIRA_LOG() the log messages will be passed to the log sinks independent from the current severity level and build target. One can make use of LogCustomizableFilter to modify the severity levels for different log sinks.

◆ MIRA_LOG_ATTR

#define MIRA_LOG_ATTR (   level,
  time,
  file,
  line,
  function,
  threadID 
)
Value:
if (level > MIRA_SEVERITY_MAX_LEVEL) {} \
else if (level > MIRA_LOGGER.getSeverityLevel()) {} \
else mira::Logger(level, time, file, line, function, threadID).stream()
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
Helper class that is created to make one logging process atomic and thread safe.
Definition: LoggingCore.h:426
#define MIRA_SEVERITY_MAX_LEVEL
Compile time defined maximum log level In release build the maximum log level should be NOTICE to eli...
Definition: LoggingCore.h:483
#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

Use this macro to log data when you have collected the log data yourself.

◆ MIRA_LOGTIMER

#define MIRA_LOGTIMER (   level,
  name,
  text 
)
Value:
LogTimer name(level, #name, Time::now(), \
__FILE__, __LINE__, \
MIRA_FUNCTION, getCurrentThreadID(), text);
#define MIRA_FUNCTION
Definition: Platform.h:98

Macro for starting a LogTimer.

◆ MIRA_PEEKLOGTIMER

#define MIRA_PEEKLOGTIMER (   name)    name.peek();

Macro for peeking LogTimer class at a defined point.

◆ MIRA_ENDLOGTIMER

#define MIRA_ENDLOGTIMER (   name)    name.end();

Macro for ending LogTimer class at a defined point.

Enumeration Type Documentation

◆ SeverityLevel

Severity levels to graduate between different log outputs.

Enumerator
CRITICAL 
ERROR 
WARNING 
NOTICE 
DEBUG 
TRACE 

Function Documentation

◆ operator &()

LogCustomizableFilter::AndOperator<Derived1, Derived2> mira::operator& ( const LogCustomizableFilter::CustomFilter< Derived1 > &  f1,
const LogCustomizableFilter::CustomFilter< Derived2 > &  f2 
)

Operator to combine filters by and.

◆ operator|()

LogCustomizableFilter::OrOperator<Derived1, Derived2> mira::operator| ( const LogCustomizableFilter::CustomFilter< Derived1 > &  f1,
const LogCustomizableFilter::CustomFilter< Derived2 > &  f2 
)

Operator to combine filters by or.

◆ stringToSeverityLevel()

MIRA_BASE_EXPORT SeverityLevel mira::stringToSeverityLevel ( const std::string &  levelString)

Converts the specified string into a numeric severity level.

Exceptions
XInvalidParameter,ifthe string does not name a valid level.