Tomographer  v4.0
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
 The base logger type (see class documentation)
 
typedef _PARENT_LOGGER_TYPE ParentLoggerType
 Type of the parent logger type, ultimately responsible for actually emitting the messages in some useful way. More...
 
- 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_)
 Construct a local logger. More...
 
 LocalLogger (const std::string &origin_prefix, const std::string &glue, BaseLoggerType &logger_)
 Construct a local logger. More...
 
 LocalLogger (const LocalLoggerOriginSpec &spec, BaseLoggerType &logger_)
 Construct a local logger. More...
 
 LocalLogger (LocalLogger &&movecopy)
 
 LocalLogger (const LocalLogger &other)
 Make the local-logger copyable – there's nothing wrong with that.
 
std::string originPrefix () const
 The fixed origin specified at the constructor. More...
 
std::string glue () const
 The "glue" string to use to concatenate origins from sub-loggers.
 
BaseLoggerTypebaseLogger ()
 The base logger type specified to the constructor. More...
 
ParentLoggerTypeparentLogger ()
 The parent logger responsible for actually emitting the messages in some useful way. More...
 
LocalLogger< LocalLogger< BaseLoggerType > > subLogger (const std::string &new_prefix)
 Create a sub-logger. More...
 
LocalLogger< LocalLogger< BaseLoggerType > > subLogger (const std::string &new_prefix, const std::string &new_glue)
 Create a sub-logger. More...
 
LocalLogger< LocalLogger< BaseLoggerType > > subLogger (const LocalLoggerOriginSpec &spec)
 Create a sub-logger. More...
 
void longdebug (const char *fmt,...)
 Generate a log message with level Logger::LONGDEBUG (printf-like syntax) More...
 
void debug (const char *fmt,...)
 Generate a log message with level Logger::DEBUG (printf-like syntax) More...
 
void info (const char *fmt,...)
 Generate a log message with level Logger::INFO (printf-like syntax) More...
 
void warning (const char *fmt,...)
 Generate a log message with level Logger::WARNING (printf-like syntax) More...
 
void error (const char *fmt,...)
 Generate a log message with level Logger::ERROR (printf-like syntax) More...
 
template<typename... Args>
void longdebug (Args &&... a)
 Generate a log message with level Logger::LONGDEBUG. More...
 
template<typename... Args>
void debug (Args &&... a)
 Generate a log message with level Logger::DEBUG. More...
 
template<typename... Args>
void info (Args &&... a)
 Generate a log message with level Logger::INFO. More...
 
template<typename... Args>
void warning (Args &&... a)
 Generate a log message with level Logger::WARNING. More...
 
template<typename... Args>
void error (Args &&... a)
 Generate a log message with level Logger::ERROR. More...
 
template<int Level, typename... Args>
void log (Args... args)
 Generate a log message with level Level. More...
 
std::string getSubOrigin (const char *origin) const
 The full origin string to use for a sub-logger. More...
 
void emitLog (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 filterByOrigin (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 enabledFor (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 staticallyEnabledFor (int level)
 Check whether the logger is statically disabled for some levels. More...
 
static bool staticallyEnabledFor ()
 Static version of staticallyEnabledFor() 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 having to specify the origin information, which is known from the constructor.

This logger is to be used with another logger instance, which is actually responsible for producing the log messages. This logger then relays log messages that base logger instance, of type BaseLoggerType (for example, FileLogger, BufferLogger etc.).

You may also nest these loggers, yielding an automatic nested origin string following C++ names. See method subLogger(const std::string&) for more info. In case of nesting, what happens is that the BaseLoggerType is a LocalLogger itself.

A very handy shorthand is makeLocalLogger(), which allows to spare some typing (see documentation for makeLocalLogger()).

The macro TOMO_ORIGIN is particularly useful for this class, as you can specify it in the origin parameter to automatically yield the name of the current method.

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
// parentLogger() as the other routine expects to be able to specify its
// own origin string:
some_external_routine(k, .., _logger.parentLogger());
}
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 1665 of file loggers.h.

Member Typedef Documentation

§ ParentLoggerType

template<typename BaseLoggerType_>
typedef _PARENT_LOGGER_TYPE Tomographer::Logger::LocalLogger< BaseLoggerType_ >::ParentLoggerType

Type of the parent logger type, ultimately responsible for actually emitting the messages in some useful way.

See parentLogger().

Definition at line 1864 of file loggers.h.

Constructor & Destructor Documentation

§ LocalLogger() [1/4]

template<typename BaseLoggerType_>
Tomographer::Logger::LocalLogger< BaseLoggerType_ >::LocalLogger ( const std::string origin_fn_name,
BaseLoggerType logger_ 
)
inline

Construct a local logger.

Parameters
origin_fn_nameis the origin you want to associate with log messages generated by this logger. You may also use the macro TOMO_ORIGIN for this argument to automatically set the origin to the current function or method name.
logger_is a logger instance of type BaseLoggerType, which is responsible for actually emitting the messages in some useful way (e.g. it may be a FileLogger, BufferLogger, etc.)

Definition at line 1787 of file loggers.h.

§ LocalLogger() [2/4]

template<typename BaseLoggerType_>
Tomographer::Logger::LocalLogger< BaseLoggerType_ >::LocalLogger ( const std::string origin_prefix,
const std::string glue,
BaseLoggerType logger_ 
)
inline

Construct a local logger.

See LocalLogger(const std::string&, BaseLoggerType&). This overload allows you to also specify the glue to use when concatenating origins for sub-loggers, see glue() and subLogger().

Definition at line 1798 of file loggers.h.

§ LocalLogger() [3/4]

template<typename BaseLoggerType_>
Tomographer::Logger::LocalLogger< BaseLoggerType_ >::LocalLogger ( const LocalLoggerOriginSpec spec,
BaseLoggerType logger_ 
)
inline

Construct a local logger.

See LocalLogger(const std::string&, BaseLoggerType&). This overload is the one which is called if you use the macro TOMO_ORIGIN for the first argument.

Definition at line 1808 of file loggers.h.

§ LocalLogger() [4/4]

template<typename BaseLoggerType_>
Tomographer::Logger::LocalLogger< BaseLoggerType_ >::LocalLogger ( LocalLogger< BaseLoggerType_ > &&  movecopy)
inline

We need this for makeLocalLogger().

Definition at line 1818 of file loggers.h.

Member Function Documentation

§ baseLogger()

template<typename BaseLoggerType_>
BaseLoggerType& Tomographer::Logger::LocalLogger< BaseLoggerType_ >::baseLogger ( )
inline

The base logger type specified to the constructor.

If we are a sub-logger of another local logger, then BaseLoggerType is itself also a LocalLogger.

Definition at line 1856 of file loggers.h.

§ debug() [1/2]

template<typename BaseLoggerType_>
void Tomographer::Logger::LocalLogger< BaseLoggerType_ >::debug ( const char *  fmt,
  ... 
)
inline

Generate a log message with level Logger::DEBUG (printf-like syntax)

The origin parameter is automatically set, and is not specified here.

Definition at line 1933 of file loggers.h.

§ debug() [2/2]

template<typename BaseLoggerType_>
template<typename... Args>
void Tomographer::Logger::LocalLogger< BaseLoggerType_ >::debug ( Args &&...  a)
inline

Generate a log message with level Logger::DEBUG.

The origin parameter is automatically set, and is not specified here.

Definition at line 1965 of file loggers.h.

§ error() [1/2]

template<typename BaseLoggerType_>
void Tomographer::Logger::LocalLogger< BaseLoggerType_ >::error ( const char *  fmt,
  ... 
)
inline

Generate a log message with level Logger::ERROR (printf-like syntax)

The origin parameter is automatically set, and is not specified here.

Definition at line 1951 of file loggers.h.

§ error() [2/2]

template<typename BaseLoggerType_>
template<typename... Args>
void Tomographer::Logger::LocalLogger< BaseLoggerType_ >::error ( Args &&...  a)
inline

Generate a log message with level Logger::ERROR.

The origin parameter is automatically set, and is not specified here.

Definition at line 1983 of file loggers.h.

§ getSubOrigin()

template<typename BaseLoggerType_>
std::string Tomographer::Logger::LocalLogger< BaseLoggerType_ >::getSubOrigin ( const char *  origin) const
inline

The full origin string to use for a sub-logger.

This simply returns the concatenation of originPrefix() with origin using the glue().

It is the full origin parameter which is used when creating sub-loggers of this logger (see subLogger()).

Definition at line 2006 of file loggers.h.

§ info() [1/2]

template<typename BaseLoggerType_>
void Tomographer::Logger::LocalLogger< BaseLoggerType_ >::info ( const char *  fmt,
  ... 
)
inline

Generate a log message with level Logger::INFO (printf-like syntax)

The origin parameter is automatically set, and is not specified here.

Definition at line 1939 of file loggers.h.

§ info() [2/2]

template<typename BaseLoggerType_>
template<typename... Args>
void Tomographer::Logger::LocalLogger< BaseLoggerType_ >::info ( Args &&...  a)
inline

Generate a log message with level Logger::INFO.

The origin parameter is automatically set, and is not specified here.

Definition at line 1971 of file loggers.h.

§ log()

template<typename BaseLoggerType_>
template<int Level, typename... Args>
void Tomographer::Logger::LocalLogger< BaseLoggerType_ >::log ( Args...  args)
inline

Generate a log message with level Level.

The origin parameter is automatically set, and is not specified here.

Definition at line 1990 of file loggers.h.

§ longdebug() [1/2]

template<typename BaseLoggerType_>
void Tomographer::Logger::LocalLogger< BaseLoggerType_ >::longdebug ( const char *  fmt,
  ... 
)
inline

Generate a log message with level Logger::LONGDEBUG (printf-like syntax)

The origin parameter is automatically set, and is not specified here.

Definition at line 1927 of file loggers.h.

§ longdebug() [2/2]

template<typename BaseLoggerType_>
template<typename... Args>
void Tomographer::Logger::LocalLogger< BaseLoggerType_ >::longdebug ( Args &&...  a)
inline

Generate a log message with level Logger::LONGDEBUG.

The origin parameter is automatically set, and is not specified here.

Definition at line 1959 of file loggers.h.

§ originPrefix()

template<typename BaseLoggerType_>
std::string Tomographer::Logger::LocalLogger< BaseLoggerType_ >::originPrefix ( ) const
inline

The fixed origin specified at the constructor.

This will be used as origin if you call one of the logging functions longdebug(), debug(), info(), warning(), error() or log<LEVEL>().

This string will also be used as a "prefix" for sub-loggers.

Definition at line 1845 of file loggers.h.

§ parentLogger()

template<typename BaseLoggerType_>
ParentLoggerType& Tomographer::Logger::LocalLogger< BaseLoggerType_ >::parentLogger ( )
inline

The parent logger responsible for actually emitting the messages in some useful way.

This function returns baseLogger() if the BaseLoggerType is not a LocalLogger. Otherwise, it follows the base loggers of the LocalLoggers until a non-LocalLogger parent is found; the latter is returned.

Definition at line 1873 of file loggers.h.

§ subLogger() [1/3]

template<typename BaseLoggerType_>
LocalLogger<LocalLogger<BaseLoggerType> > Tomographer::Logger::LocalLogger< BaseLoggerType_ >::subLogger ( const std::string new_prefix)
inline

Create a sub-logger.

The origin of the messages generated by this new sub-logger will be the concatenation of the parent (this) logger's origin, with the new_prefix, using the parent (this) object's glue() string.

You may use the macro TOMO_ORIGIN as argument here to automatically set the origin to the current function or method name.

Definition at line 1898 of file loggers.h.

§ subLogger() [2/3]

template<typename BaseLoggerType_>
LocalLogger<LocalLogger<BaseLoggerType> > Tomographer::Logger::LocalLogger< BaseLoggerType_ >::subLogger ( const std::string new_prefix,
const std::string new_glue 
)
inline

Create a sub-logger.

See subLogger(const std::string &). This overload allows to specify the new object's glue string, which will be used in case the sub-logger itself becomes parent to a (sub-)sub-logger.

Definition at line 1908 of file loggers.h.

§ subLogger() [3/3]

template<typename BaseLoggerType_>
LocalLogger<LocalLogger<BaseLoggerType> > Tomographer::Logger::LocalLogger< BaseLoggerType_ >::subLogger ( const LocalLoggerOriginSpec spec)
inline

Create a sub-logger.

See subLogger(const std::string &). This overload is called when the macro TOMO_ORIGIN is specified.

Definition at line 1918 of file loggers.h.

§ warning() [1/2]

template<typename BaseLoggerType_>
void Tomographer::Logger::LocalLogger< BaseLoggerType_ >::warning ( const char *  fmt,
  ... 
)
inline

Generate a log message with level Logger::WARNING (printf-like syntax)

The origin parameter is automatically set, and is not specified here.

Definition at line 1945 of file loggers.h.

§ warning() [2/2]

template<typename BaseLoggerType_>
template<typename... Args>
void Tomographer::Logger::LocalLogger< BaseLoggerType_ >::warning ( Args &&...  a)
inline

Generate a log message with level Logger::WARNING.

The origin parameter is automatically set, and is not specified here.

Definition at line 1977 of file loggers.h.


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