Tomographer  v1.0a
Tomographer C++ Framework Documentation
Tomographer::Logger::LocalLogger< BaseLoggerType_ > Class Template Reference

Local logger: avoid having to repeat origin at each emitted message. More...

#include <tomographer/tools/loggers.h>

+ Inheritance diagram for Tomographer::Logger::LocalLogger< BaseLoggerType_ >:
+ Collaboration diagram for Tomographer::Logger::LocalLogger< BaseLoggerType_ >:

Public Types

typedef BaseLoggerType_ BaseLoggerType
 
- Public Types inherited from Tomographer::Logger::LoggerBase< LocalLogger< BaseLoggerType_ > >
enum  
 Shortcuts to properties defined in the traits class.
 

Public Member Functions

 LocalLogger (const std::string &origin_fn_name, BaseLoggerType &logger_)
 
 LocalLogger (const std::string &origin_prefix, const std::string &glue, BaseLoggerType &logger_)
 
 LocalLogger (const LocalLoggerOriginSpec &spec, BaseLoggerType &logger_)
 
std::string origin_prefix () const
 
std::string glue () const
 
BaseLoggerType & baselogger ()
 
LocalLogger< LocalLogger< BaseLoggerType > > sublogger (const std::string &new_prefix)
 
LocalLogger< LocalLogger< BaseLoggerType > > sublogger (const std::string &new_prefix, const std::string &new_glue)
 
LocalLogger< LocalLogger< BaseLoggerType > > sublogger (const LocalLoggerOriginSpec &spec)
 
void longdebug (const char *fmt,...)
 
void debug (const char *fmt,...)
 
void info (const char *fmt,...)
 
void warning (const char *fmt,...)
 
void error (const char *fmt,...)
 
template<typename... Args>
void longdebug (Args...a)
 
template<typename... Args>
void debug (Args...a)
 
template<typename... Args>
void info (Args...a)
 
template<typename... Args>
void warning (Args...a)
 
template<typename... Args>
void error (Args...a)
 
template<int Level, typename... Args>
void log (Args...args)
 
std::string get_origin (const char *origin) const
 
void emit_log (int level, const char *origin, const std::string &msg)
 Emit a log by relaying to the base logger.
 
int level () const
 Get the base logger's set level.
 
template<ENABLED_IF(Tomographer::Logger::LoggerTraits< BaseLoggerType >::HasFilterByOrigin) >
bool filter_by_origin (int level, const char *origin)
 If relevant for the base logger, filter the messages by origin from the base logger.
 
- Public Member Functions inherited from Tomographer::Logger::LoggerBase< LocalLogger< BaseLoggerType_ > >
 LoggerBase (int level_=INFO)
 Construct the base logger object. More...
 
void error (const char *origin, const char *fmt,...)
 emit an error message More...
 
void error (const char *origin, const std::string &msg)
 emit an error message More...
 
void error (const char *origin, Fn f)
 emit an error message More...
 
void warning (const char *origin, const char *fmt,...)
 emit a warning message More...
 
void warning (const char *origin, const std::string &msg)
 emit a warning message More...
 
void warning (const char *origin, Fn f)
 emit a warning message More...
 
void info (const char *origin, const char *fmt,...)
 emit an information/notice message More...
 
void info (const char *origin, const std::string &msg)
 emit an information/notice message More...
 
void info (const char *origin, Fn f)
 emit an information/notice message More...
 
void debug (const char *origin, const char *fmt,...)
 emit an debug message More...
 
void debug (const char *origin, const std::string &msg)
 emit an debug message More...
 
void debug (const char *origin, Fn f)
 emit an debug message More...
 
void longdebug (const char *origin, const char *fmt,...)
 emit a very verbose debugging message More...
 
void longdebug (const char *origin, const std::string &msg)
 emit a very verbose debugging message More...
 
void longdebug (const char *origin, Fn f)
 emit a very verbose debugging message More...
 
void log (int level, const char *origin, const char *fmt,...)
 emit a log message at the given log level. More...
 
void log (int level, const char *origin, const std::string &msg)
 emit a log message at the given log level. More...
 
void log (int level, const char *origin, Fn f)
 emit a log message at the given log level. More...
 
void log (const char *origin, const char *fmt,...)
 emit a log message at the given log level. More...
 
void log (const char *origin, const char *fmt, va_list ap)
 emit a log message at the given log level. More...
 
void log (const char *origin, const std::string &msg)
 emit a log message at the given log level. More...
 
void log (const char *origin, Fn f)
 emit a log message at the given log level. More...
 
bool enabled_for (int level_) const
 Check whether messages at the given log level are enabled. More...
 
int level () const
 Get the log level set for this logger. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from Tomographer::Logger::LoggerBase< LocalLogger< BaseLoggerType_ > >
static bool statically_enabled_for (int level)
 Check whether the logger is statically disabled for some levels. More...
 
static bool statically_enabled_for ()
 Static version of statically_enabled_for() More...
 
- Protected Member Functions inherited from Tomographer::Logger::LoggerBase< LocalLogger< BaseLoggerType_ > >
int getLevel () const
 
int getLevel () const
 
LocalLogger< BaseLoggerType_ > * derived ()
 
const LocalLogger< BaseLoggerType_ > * derived () const
 
void setLogLevel (int level)
 Store a new run-time log level. More...
 

Detailed Description

template<typename BaseLoggerType_>
class Tomographer::Logger::LocalLogger< BaseLoggerType_ >

Local logger: avoid having to repeat origin at each emitted message.

This type of logger accepts origin information in its constructor. Then, you may call the longdebug(), debug(), info(), warning() and error() methods without any origin information. You may also nest these loggers. See method sublogger(const std::string&).

This logger relays log messages to a base logger of type BaseLoggerType.

Example usage:

template<typename BaseLoggerType>
class XYZ
{
LocalLogger<BaseLoggerType> _logger;
public:
XYZ(BaseLoggerType & baselogger)
: _logger(TOMO_ORIGIN, baselogger)
{
// this message's origin will be "XYZ"
_logger.debug("constructor was called.");
}
void method(int k)
{
// this message's origin will be "XYZ"
_logger.debug("method() was called. k=%d", k);
// if you need to pass a logger to any external procedure, pass on the
// baselogger() as the other routine expects to be able to specify its
// own origin string:
some_external_routine(k, .., _logger.baselogger());
}
void longmethod(int N)
{
auto logger = _logger.sublogger(TOMO_ORIGIN);
for (int k = 0; k < N; ++k) {
// this message's origin will be "XYZ::longmethod()"
logger.debug("inner loop: k=%d out of %d", k, N);
}
}
};

Definition at line 1657 of file loggers.h.


The documentation for this class was generated from the following file: