Tomographer  v5.4
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 (std::string origin_fn_name, BaseLoggerType &logger_)
 Construct a local logger. More...
 
 LocalLogger (std::string origin_prefix, 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 (std::string new_prefix)
 Create a sub-logger. More...
 
LocalLogger< LocalLogger< BaseLoggerType > > subLogger (std::string new_prefix, std::string new_glue)
 Create a sub-logger. More...
 
LocalLogger< LocalLogger< BaseLoggerType > > subLogger (const LocalLoggerOriginSpec &spec)
 Create a sub-logger. More...
 
template<ENABLED_IF( Base_::template staticallyEnabledFor< LONGDEBUG >()) >
void longdebug (const char *fmt,...)
 Generate a log message with level Logger::LONGDEBUG (printf-like syntax) More...
 
template<ENABLED_IF( Base_::template staticallyEnabledFor< DEBUG >()) >
void debug (const char *fmt,...)
 Generate a log message with level Logger::DEBUG (printf-like syntax) More...
 
template<ENABLED_IF( Base_::template staticallyEnabledFor< INFO >()) >
void info (const char *fmt,...)
 Generate a log message with level Logger::INFO (printf-like syntax) More...
 
template<ENABLED_IF( Base_::template staticallyEnabledFor< WARNING >()) >
void warning (const char *fmt,...)
 Generate a log message with level Logger::WARNING (printf-like syntax) More...
 
template<ENABLED_IF( Base_::template staticallyEnabledFor< ERROR >()) >
void error (const char *fmt,...)
 Generate a log message with level Logger::ERROR (printf-like syntax) More...
 
template<ENABLED_IF( Base_::template staticallyEnabledFor< LONGDEBUG >()) , typename... Args>
void longdebug (Args &&... a)
 Generate a log message with level Logger::LONGDEBUG. More...
 
template<ENABLED_IF( Base_::template staticallyEnabledFor< DEBUG >()) , typename... Args>
void debug (Args &&... a)
 Generate a log message with level Logger::DEBUG. More...
 
template<ENABLED_IF( Base_::template staticallyEnabledFor< INFO >()) , typename... Args>
void info (Args &&... a)
 Generate a log message with level Logger::INFO. More...
 
template<ENABLED_IF( Base_::template staticallyEnabledFor< WARNING >()) , typename... Args>
void warning (Args &&... a)
 Generate a log message with level Logger::WARNING. More...
 
template<ENABLED_IF( Base_::template staticallyEnabledFor< ERROR >()) , typename... Args>
void error (Args &&... a)
 Generate a log message with level Logger::ERROR. More...
 
template<int Level, ENABLED_IF( Base_::template staticallyEnabledFor< Level >()) , typename... Args>
void log (Args &&... args)
 Generate a log message with level Level. More...
 
template<ENABLED_IF( !Base_::template staticallyEnabledFor< LONGDEBUG >()) , typename... Args>
void longdebug (Args &&...)
 Statically optimized call if we know at compile time that the message will be discarded.
 
template<ENABLED_IF( !Base_::template staticallyEnabledFor< DEBUG >()) , typename... Args>
void debug (Args &&...)
 Statically optimized call if we know at compile time that the message will be discarded.
 
template<ENABLED_IF( !Base_::template staticallyEnabledFor< INFO >()) , typename... Args>
void info (Args &&...)
 Statically optimized call if we know at compile time that the message will be discarded.
 
template<ENABLED_IF( !Base_::template staticallyEnabledFor< WARNING >()) , typename... Args>
void warning (Args &&...)
 Statically optimized call if we know at compile time that the message will be discarded.
 
template<ENABLED_IF( !Base_::template staticallyEnabledFor< ERROR >()) , typename... Args>
void error (Args &&...)
 Statically optimized call if we know at compile time that the message will be discarded.
 
template<int Level, ENABLED_IF( !Base_::template staticallyEnabledFor< Level >()) , typename... Args>
void log (Args &&...)
 Statically optimized call if we know at compile time that the message will be discarded.
 
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, 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...
 
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...
 
void error (const char *origin, const char *fmt,...)
 emit an error message More...
 
void error (const char *origin, std::string msg)
 emit an error message More...
 
void error (const char *origin, Fn &&f)
 emit an error message More...
 
void error (Args &&...)
 Special-case implementation for messages which are known to be discarded at compile time.
 
void warning (const char *origin, const char *fmt,...)
 emit a warning message More...
 
void warning (const char *origin, std::string msg)
 emit a warning message More...
 
void warning (const char *origin, Fn &&f)
 emit a warning message More...
 
void warning (Args &&...)
 Special-case implementation for messages which are known to be discarded at compile time.
 
void info (const char *origin, const char *fmt,...)
 emit an information/notice message More...
 
void info (const char *origin, std::string msg)
 emit an information/notice message More...
 
void info (const char *origin, Fn &&f)
 emit an information/notice message More...
 
void info (Args &&...)
 Special-case implementation for messages which are known to be discarded at compile time.
 
void debug (const char *origin, const char *fmt,...)
 emit an debug message More...
 
void debug (const char *origin, std::string msg)
 emit an debug message More...
 
void debug (const char *origin, Fn &&f)
 emit an debug message More...
 
void debug (Args &&...)
 Special-case implementation for messages which are known to be discarded at compile time.
 
void longdebug (const char *origin, const char *fmt,...)
 emit a very verbose debugging message More...
 
void longdebug (const char *origin, 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 longdebug (Args &&...)
 Special-case implementation for messages which are known to be discarded at compile time.
 
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, 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, 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...
 
void log (Args &&...)
 Special-case implementation for messages which are known to be discarded at compile time.
 

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 constexpr 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(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 1613 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 1812 of file loggers.h.

Constructor & Destructor Documentation

§ LocalLogger() [1/4]

template<typename BaseLoggerType_>
Tomographer::Logger::LocalLogger< BaseLoggerType_ >::LocalLogger ( 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 1735 of file loggers.h.

§ LocalLogger() [2/4]

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

Construct a local logger.

See LocalLogger(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 1746 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(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 1756 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 1766 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 1804 of file loggers.h.

§ debug() [1/2]

template<typename BaseLoggerType_>
template<ENABLED_IF( Base_::template staticallyEnabledFor< DEBUG >()) >
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 1883 of file loggers.h.

§ debug() [2/2]

template<typename BaseLoggerType_>
template<ENABLED_IF( Base_::template staticallyEnabledFor< DEBUG >()) , 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 1920 of file loggers.h.

§ error() [1/2]

template<typename BaseLoggerType_>
template<ENABLED_IF( Base_::template staticallyEnabledFor< ERROR >()) >
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 1904 of file loggers.h.

§ error() [2/2]

template<typename BaseLoggerType_>
template<ENABLED_IF( Base_::template staticallyEnabledFor< ERROR >()) , 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 1941 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 1992 of file loggers.h.

§ info() [1/2]

template<typename BaseLoggerType_>
template<ENABLED_IF( Base_::template staticallyEnabledFor< INFO >()) >
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 1890 of file loggers.h.

§ info() [2/2]

template<typename BaseLoggerType_>
template<ENABLED_IF( Base_::template staticallyEnabledFor< INFO >()) , 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 1927 of file loggers.h.

§ log()

template<typename BaseLoggerType_>
template<int Level, ENABLED_IF( Base_::template staticallyEnabledFor< 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 1950 of file loggers.h.

§ longdebug() [1/2]

template<typename BaseLoggerType_>
template<ENABLED_IF( Base_::template staticallyEnabledFor< LONGDEBUG >()) >
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 1876 of file loggers.h.

§ longdebug() [2/2]

template<typename BaseLoggerType_>
template<ENABLED_IF( Base_::template staticallyEnabledFor< LONGDEBUG >()) , 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 1913 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 1793 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 1821 of file loggers.h.

§ subLogger() [1/3]

template<typename BaseLoggerType_>
LocalLogger<LocalLogger<BaseLoggerType> > Tomographer::Logger::LocalLogger< BaseLoggerType_ >::subLogger ( 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 1846 of file loggers.h.

§ subLogger() [2/3]

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

Create a sub-logger.

See subLogger(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 1856 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(std::string). This overload is called when the macro TOMO_ORIGIN is specified.

Definition at line 1866 of file loggers.h.

§ warning() [1/2]

template<typename BaseLoggerType_>
template<ENABLED_IF( Base_::template staticallyEnabledFor< WARNING >()) >
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 1897 of file loggers.h.

§ warning() [2/2]

template<typename BaseLoggerType_>
template<ENABLED_IF( Base_::template staticallyEnabledFor< WARNING >()) , 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 1934 of file loggers.h.


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