Tomographer  v5.4
Tomographer C++ Framework Documentation
Tomographer::Logger::LoggerBase< Derived > Class Template Reference

Base logger class. More...

#include <tomographer/tools/loggers.h>

+ Inheritance diagram for Tomographer::Logger::LoggerBase< Derived >:

Public Types

enum  
 Shortcuts to properties defined in the traits class. More...
 

Public Member Functions

 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...
 
template<ENABLED_IF( staticallyEnabledFor< ERROR >()) >
void error (const char *origin, const char *fmt,...)
 emit an error message More...
 
template<ENABLED_IF( staticallyEnabledFor< ERROR >()) >
void error (const char *origin, std::string msg)
 emit an error message More...
 
template<typename Fn , ENABLED_IF( staticallyEnabledFor< ERROR >() && tomo_internal::IsOstreamArgCallable< Fn >::value) >
void error (const char *origin, Fn &&f)
 emit an error message More...
 
template<ENABLED_IF( !staticallyEnabledFor< ERROR >()) , typename... Args>
void error (Args &&...)
 Special-case implementation for messages which are known to be discarded at compile time.
 
template<ENABLED_IF( staticallyEnabledFor< WARNING >()) >
void warning (const char *origin, const char *fmt,...)
 emit a warning message More...
 
template<ENABLED_IF( staticallyEnabledFor< WARNING >()) >
void warning (const char *origin, std::string msg)
 emit a warning message More...
 
template<typename Fn , ENABLED_IF( staticallyEnabledFor< WARNING >() && tomo_internal::IsOstreamArgCallable< Fn >::value) >
void warning (const char *origin, Fn &&f)
 emit a warning message More...
 
template<ENABLED_IF( !staticallyEnabledFor< WARNING >()) , typename... Args>
void warning (Args &&...)
 Special-case implementation for messages which are known to be discarded at compile time.
 
template<ENABLED_IF( staticallyEnabledFor< INFO >()) >
void info (const char *origin, const char *fmt,...)
 emit an information/notice message More...
 
template<ENABLED_IF( staticallyEnabledFor< INFO >()) >
void info (const char *origin, std::string msg)
 emit an information/notice message More...
 
template<typename Fn , ENABLED_IF( staticallyEnabledFor< INFO >() && tomo_internal::IsOstreamArgCallable< Fn >::value) >
void info (const char *origin, Fn &&f)
 emit an information/notice message More...
 
template<ENABLED_IF( !staticallyEnabledFor< INFO >()) , typename... Args>
void info (Args &&...)
 Special-case implementation for messages which are known to be discarded at compile time.
 
template<ENABLED_IF( staticallyEnabledFor< DEBUG >()) >
void debug (const char *origin, const char *fmt,...)
 emit an debug message More...
 
template<ENABLED_IF( staticallyEnabledFor< DEBUG >()) >
void debug (const char *origin, std::string msg)
 emit an debug message More...
 
template<typename Fn , ENABLED_IF( staticallyEnabledFor< DEBUG >() && tomo_internal::IsOstreamArgCallable< Fn >::value) >
void debug (const char *origin, Fn &&f)
 emit an debug message More...
 
template<ENABLED_IF( !staticallyEnabledFor< DEBUG >()) , typename... Args>
void debug (Args &&...)
 Special-case implementation for messages which are known to be discarded at compile time.
 
template<ENABLED_IF( staticallyEnabledFor< LONGDEBUG >()) >
void longdebug (const char *origin, const char *fmt,...)
 emit a very verbose debugging message More...
 
template<ENABLED_IF( staticallyEnabledFor< LONGDEBUG >()) >
void longdebug (const char *origin, std::string msg)
 emit a very verbose debugging message More...
 
template<typename Fn , ENABLED_IF( staticallyEnabledFor< LONGDEBUG >() && tomo_internal::IsOstreamArgCallable< Fn >::value) >
void longdebug (const char *origin, Fn &&f)
 emit a very verbose debugging message More...
 
template<ENABLED_IF( !staticallyEnabledFor< LONGDEBUG >()) , typename... Args>
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...
 
template<typename Fn , ENABLED_IF( tomo_internal::IsOstreamArgCallable< Fn >::value) >
void log (int level, const char *origin, Fn &&f)
 emit a log message at the given log level. More...
 
template<int Level, ENABLED_IF( staticallyEnabledFor< Level >()) >
void log (const char *origin, const char *fmt,...)
 emit a log message at the given log level. More...
 
template<int Level, ENABLED_IF( staticallyEnabledFor< Level >()) >
void log (const char *origin, const char *fmt, va_list ap)
 emit a log message at the given log level. More...
 
template<int Level, ENABLED_IF( staticallyEnabledFor< Level >()) >
void log (const char *origin, std::string msg)
 emit a log message at the given log level. More...
 
template<int Level, typename Fn , ENABLED_IF( staticallyEnabledFor< Level >() && tomo_internal::IsOstreamArgCallable< Fn >::value) >
void log (const char *origin, Fn f)
 emit a log message at the given log level. More...
 
template<int Level, ENABLED_IF( !staticallyEnabledFor< Level >()) , typename ... Args>
void log (Args &&...)
 Special-case implementation for messages which are known to be discarded at compile time.
 

Static Public Member Functions

static bool staticallyEnabledFor (int level)
 Check whether the logger is statically disabled for some levels. More...
 
template<int Level>
static constexpr bool staticallyEnabledFor ()
 Static version of staticallyEnabledFor() More...
 

Protected Member Functions

template<ENABLED_IF( !HasOwnGetLevel) >
int getLevel () const
 
template<ENABLED_IF( HasOwnGetLevel) >
int getLevel () const
 
Derived * derived ()
 
const Derived * derived () const
 
void setLogLevel (int level)
 Store a new run-time log level. More...
 

Detailed Description

template<typename Derived>
class Tomographer::Logger::LoggerBase< Derived >

Base logger class.

Please read Logging and Loggers to understand Tomographer's logging framework.

This class serves as base class for logger implementations. It provides storing a current given level, emitting the log only if the level is reached, etc. Don't instantiate this class directly.

See also FileLogger.

A logger always has a level set at run-time, which can always be retrieved by calling level(). By default, this class stores the level given to the constructor. If you want your derived class to store its own level, or simply to relay log messages to a further logger and inherit its level, then you should declare HasOwnGetLevel=1 in your logger traits (see LoggerTraits), and provide your own level() method, which should be const and return an int.

Also, by default there is no public setLevel() method, in case your logger's level is statically fixed or otherwise can't be changed, or if you need a thread-safe logger. Derived classes may set the logger's level (again, only if HasOwnGetLevel=0) by calling the protected setLogLevel(int). You may of course then also expose a public function such as setLevel() which calls setLogLevel(), if you want (see, for example, FileLogger).

Definition at line 444 of file loggers.h.

Member Enumeration Documentation

§ anonymous enum

template<typename Derived>
anonymous enum

Shortcuts to properties defined in the traits class.

Enumerator
IsThreadSafe 

See LoggerTraits<Derived> and DefaultLoggerTraits.

StaticMinimumSeverityLevel 

See LoggerTraits<Derived> and DefaultLoggerTraits.

HasOwnGetLevel 

See LoggerTraits<Derived> and DefaultLoggerTraits.

HasFilterByOrigin 

See LoggerTraits<Derived> and DefaultLoggerTraits.

Definition at line 452 of file loggers.h.

Constructor & Destructor Documentation

§ LoggerBase()

template<typename Derived>
Tomographer::Logger::LoggerBase< Derived >::LoggerBase ( int  level_ = INFO)
inline

Construct the base logger object.

The logging level is set to level, by default Logger::INFO. Any messages with lesser severity will be automatically discarded.

Note that if the derived logger class provides its own level() method, and declares it with LoggerTraits<Derived>::HasOwnGetLevel, then the level provided here is discarded and ignored.

Definition at line 472 of file loggers.h.

Member Function Documentation

§ debug() [1/3]

template<typename Derived>
template<ENABLED_IF( staticallyEnabledFor< DEBUG >()) >
void Tomographer::Logger::LoggerBase< Derived >::debug ( const char *  origin,
const char *  fmt,
  ... 
)
inline

emit an debug message

Call this method to report a debugging message with this logger. This will relay the the call to the underlying logger implementation (subclass) if logging at the level Logger::DEBUG is enabled.

This method overload allows you to format messages in a printf -like fashion. The final message will be formatted using an actual function of the sprintf() family.

See Logging and Loggers for more information about Tomographer's logging framework.

Parameters
originA string which identifies the place in code from where the debugging message is originating. This is useful to trace back error messages. Conventionally, specify the name of the function with its class (e.g. "MyClass::my_method()").
fmtA printf format string
...additional arguments for the printf formatting string.

Definition at line 710 of file loggers.h.

§ debug() [2/3]

template<typename Derived>
template<ENABLED_IF( staticallyEnabledFor< DEBUG >()) >
void Tomographer::Logger::LoggerBase< Derived >::debug ( const char *  origin,
std::string  msg 
)
inline

emit an debug message

Call this method to report a debugging message with this logger. This will relay the the call to the underlying logger implementation (subclass) if logging at the level Logger::DEBUG is enabled.

This method overload assumes that you have already suitably formatted your message, and will directly provide the given msg to the underlying logger implementation.

See Logging and Loggers for more information about Tomographer's logging framework.

Parameters
originA string which identifies the place in code from where the debugging message is originating. This is useful to trace back error messages. Conventionally, specify the name of the function with its class (e.g. "MyClass::my_method()").
msgthe log message to produce.

Definition at line 735 of file loggers.h.

§ debug() [3/3]

template<typename Derived>
template<typename Fn , ENABLED_IF( staticallyEnabledFor< DEBUG >() && tomo_internal::IsOstreamArgCallable< Fn >::value) >
void Tomographer::Logger::LoggerBase< Derived >::debug ( const char *  origin,
Fn &&  f 
)
inline

emit an debug message

Call this method to report a debugging message with this logger. This will relay the the call to the underlying logger implementation (subclass) if logging at the level Logger::DEBUG is enabled.

See Logging and Loggers for more information about Tomographer's logging framework.

This method overload allows you to write to the logger using the C++ stream syntax. This function takes as argument a callable f, which will be called with a std::ostream& parameter to which it can write to. This is especially handy combined with C++11 lambdas, for example:

logger.debug("origin_fn()", [value](std::ostream& stream) {
stream << "The value is: " << value;
});
Parameters
originA string which identifies the place in code from where the debugging message is originating. This is useful to trace back error messages. Conventionally, specify the name of the function with its class (e.g. "MyClass::my_method()").
fa callable which accepts a single std::ostream& argument, to which it should write its log message.

Internally, the log message is first written to a std::ostringstream before transmitting it to the underlying logger implementation. (But don't rely on this!)

Definition at line 771 of file loggers.h.

§ enabledFor()

template<typename Derived>
bool Tomographer::Logger::LoggerBase< Derived >::enabledFor ( int  level_) const
inline

Check whether messages at the given log level are enabled.

This function returns true if a message at the given level will be emitted, i.e. transmitted to the underlying logger implementation.

The condition for a log message to be emitted is that the message's log level not be explicitly disabled by LoggerTraits::StaticMinimumSeverityLevel, and that the message's log level be at least as important as the current level set for this logger (see level()).

Definition at line 517 of file loggers.h.

§ error() [1/3]

template<typename Derived>
template<ENABLED_IF( staticallyEnabledFor< ERROR >()) >
void Tomographer::Logger::LoggerBase< Derived >::error ( const char *  origin,
const char *  fmt,
  ... 
)
inline

emit an error message

Call this method to report an error.

See debug(const char *, const char *, ...) for information about the function arguments.

Definition at line 556 of file loggers.h.

§ error() [2/3]

template<typename Derived>
template<ENABLED_IF( staticallyEnabledFor< ERROR >()) >
void Tomographer::Logger::LoggerBase< Derived >::error ( const char *  origin,
std::string  msg 
)
inline

emit an error message

Call this method to report an error.

See debug(const char *, std::string) for information about the function arguments.

Definition at line 572 of file loggers.h.

§ error() [3/3]

template<typename Derived>
template<typename Fn , ENABLED_IF( staticallyEnabledFor< ERROR >() && tomo_internal::IsOstreamArgCallable< Fn >::value) >
void Tomographer::Logger::LoggerBase< Derived >::error ( const char *  origin,
Fn &&  f 
)
inline

emit an error message

Call this method to report an error.

See debug(const char *, Fn&&) for information about the function arguments.

Definition at line 586 of file loggers.h.

§ info() [1/3]

template<typename Derived>
template<ENABLED_IF( staticallyEnabledFor< INFO >()) >
void Tomographer::Logger::LoggerBase< Derived >::info ( const char *  origin,
const char *  fmt,
  ... 
)
inline

emit an information/notice message

Call this method to report an information/notice message.

See debug(const char *, const char *, ...) for information about the function arguments.

Definition at line 652 of file loggers.h.

§ info() [2/3]

template<typename Derived>
template<ENABLED_IF( staticallyEnabledFor< INFO >()) >
void Tomographer::Logger::LoggerBase< Derived >::info ( const char *  origin,
std::string  msg 
)
inline

emit an information/notice message

Call this method to report an information/notice message.

See debug(const char*, std::string) for information about the function arguments.

Definition at line 668 of file loggers.h.

§ info() [3/3]

template<typename Derived>
template<typename Fn , ENABLED_IF( staticallyEnabledFor< INFO >() && tomo_internal::IsOstreamArgCallable< Fn >::value) >
void Tomographer::Logger::LoggerBase< Derived >::info ( const char *  origin,
Fn &&  f 
)
inline

emit an information/notice message

Call this method to report an information/notice message.

See debug(const char *, Fn&&) for information about the function arguments.

Definition at line 681 of file loggers.h.

§ level()

template<typename Derived>
int Tomographer::Logger::LoggerBase< Derived >::level ( ) const
inline

Get the log level set for this logger.

This is the log level given to the constructor at run-time, or set with the protected setLogLevel() method.

This method is provided for if your own derived class doesn't provide it already, i.e. if the logger traits of your derived class declares HasOwnGetLevel to 0 or doesn't declare it. If you call this function with HasOwnGetLevel set to 1, then the derived class' method will be called. So if you override this method in the derived class with HasOwnGetLevel=1, then don't call the base implementation!

Definition at line 539 of file loggers.h.

§ log() [1/7]

template<typename Derived>
void Tomographer::Logger::LoggerBase< Derived >::log ( int  level,
const char *  origin,
const char *  fmt,
  ... 
)
inline

emit a log message at the given log level.

You should never need to call this method, and I'm not sure it's a good design choice. (Mind that messages logged here may not be statically removed if a static minimum level is set.)

Otherwise, see debug(const char *, const char *, ...) for information about the function arguments.

Definition at line 838 of file loggers.h.

§ log() [2/7]

template<typename Derived>
void Tomographer::Logger::LoggerBase< Derived >::log ( int  level,
const char *  origin,
std::string  msg 
)
inline

emit a log message at the given log level.

You should never need to call this method, and I'm not sure it's a good design choice. (Mind that messages logged here may not be statically removed if a static minimum level is set.)

Otherwise, see debug(const char*, std::string) for information about the function arguments.

Definition at line 855 of file loggers.h.

§ log() [3/7]

template<typename Derived>
template<typename Fn , ENABLED_IF( tomo_internal::IsOstreamArgCallable< Fn >::value) >
void Tomographer::Logger::LoggerBase< Derived >::log ( int  level,
const char *  origin,
Fn &&  f 
)
inline

emit a log message at the given log level.

You should never need to call this method, and I'm not sure it's a good design choice. (Mind that messages logged here may not be statically removed if a static minimum level is set.)

Otherwise, see debug(const char *, Fn&&) for information about the function arguments.

Definition at line 870 of file loggers.h.

§ log() [4/7]

template<typename Derived>
template<int Level, ENABLED_IF( staticallyEnabledFor< Level >()) >
void Tomographer::Logger::LoggerBase< Derived >::log ( const char *  origin,
const char *  fmt,
  ... 
)
inline

emit a log message at the given log level.

The log level is given statically. You shouldn't need to call this method directly, it's probably more readable to use debug(), warning(), etc.

See debug(const char *, const char *, ...) for information about the function arguments.

Definition at line 886 of file loggers.h.

§ log() [5/7]

template<typename Derived>
template<int Level, ENABLED_IF( staticallyEnabledFor< Level >()) >
void Tomographer::Logger::LoggerBase< Derived >::log ( const char *  origin,
const char *  fmt,
va_list  ap 
)
inline

emit a log message at the given log level.

The log level is given statically. You shouldn't need to call this method directly, it's probably more readable to use debug(), warning(), etc.

This function is a convenience method which accepts an argument list pointer instead of ... . The format string and argument list are expected to be the same as for log(const char * origin, const char * fmt, ...) .

Definition at line 904 of file loggers.h.

§ log() [6/7]

template<typename Derived>
template<int Level, ENABLED_IF( staticallyEnabledFor< Level >()) >
void Tomographer::Logger::LoggerBase< Derived >::log ( const char *  origin,
std::string  msg 
)
inline

emit a log message at the given log level.

The log level is given statically. You shouldn't need to call this method directly, it's probably more readable to use debug(), warning(), etc.

Otherwise, see debug(const char*, std::string) for information about the function arguments.

Definition at line 918 of file loggers.h.

§ log() [7/7]

template<typename Derived>
template<int Level, typename Fn , ENABLED_IF( staticallyEnabledFor< Level >() && tomo_internal::IsOstreamArgCallable< Fn >::value) >
void Tomographer::Logger::LoggerBase< Derived >::log ( const char *  origin,
Fn  f 
)
inline

emit a log message at the given log level.

The log level is given statically. You shouldn't need to call this method directly, it's probably more readable to use debug(), warning(), etc.

Otherwise, see debug(const char *, Fn&&) for information about the function arguments.

Definition at line 934 of file loggers.h.

§ longdebug() [1/3]

template<typename Derived>
template<ENABLED_IF( staticallyEnabledFor< LONGDEBUG >()) >
void Tomographer::Logger::LoggerBase< Derived >::longdebug ( const char *  origin,
const char *  fmt,
  ... 
)
inline

emit a very verbose debugging message

Call this method to report debugging messages which are emitted very often.

See debug(const char *, const char *, ...) for information about the function arguments.

Definition at line 789 of file loggers.h.

§ longdebug() [2/3]

template<typename Derived>
template<ENABLED_IF( staticallyEnabledFor< LONGDEBUG >()) >
void Tomographer::Logger::LoggerBase< Derived >::longdebug ( const char *  origin,
std::string  msg 
)
inline

emit a very verbose debugging message

Call this method to report debugging messages which are emitted very often.

See debug(const char*, std::string) for information about the function arguments.

Definition at line 805 of file loggers.h.

§ longdebug() [3/3]

template<typename Derived>
template<typename Fn , ENABLED_IF( staticallyEnabledFor< LONGDEBUG >() && tomo_internal::IsOstreamArgCallable< Fn >::value) >
void Tomographer::Logger::LoggerBase< Derived >::longdebug ( const char *  origin,
Fn &&  f 
)
inline

emit a very verbose debugging message

Call this method to report debugging messages which are emitted very often.

See debug(const char *, Fn&&) for information about the function arguments.

Definition at line 818 of file loggers.h.

§ setLogLevel()

template<typename Derived>
void Tomographer::Logger::LoggerBase< Derived >::setLogLevel ( int  level)
inlineprotected

Store a new run-time log level.

See also level().

The base class does not provide a public setLevel() function, in case your logger does not support setting any level, or in case you need your logger to be completely thread-safe, or for any other reason.

Subclasses may, however, change the log level by explicily calling this method. This method however should ONLY be used if your derived class doesn't define its own level() method and thus only if the logger traits HasOwnGetLogger is false. (The method is not exposed otherwise.)

Definition at line 988 of file loggers.h.

§ staticallyEnabledFor() [1/2]

template<typename Derived>
static bool Tomographer::Logger::LoggerBase< Derived >::staticallyEnabledFor ( int  level)
inlinestatic

Check whether the logger is statically disabled for some levels.

Template Parameters
Levelthe log level to test for.
Returns
false if the logger was explicitly disabled for the level Level via LoggerTraits<Derived>::StaticMinimumSeverityLevel, otherwise returns true.

If true was returned, this does not yet mean that a log message at the given level will necessarily be produced; in this case, rather, the message is not expliclty discarded and the logger's level set at run-time will be tested (see enabledFor()).

Definition at line 490 of file loggers.h.

§ staticallyEnabledFor() [2/2]

template<typename Derived>
template<int Level>
static constexpr bool Tomographer::Logger::LoggerBase< Derived >::staticallyEnabledFor ( )
inlinestatic

Static version of staticallyEnabledFor()

Definition at line 499 of file loggers.h.

§ warning() [1/3]

template<typename Derived>
template<ENABLED_IF( staticallyEnabledFor< WARNING >()) >
void Tomographer::Logger::LoggerBase< Derived >::warning ( const char *  origin,
const char *  fmt,
  ... 
)
inline

emit a warning message

Call this method to report a warning.

See debug(const char *, const char *, ...) for information about the function arguments.

Definition at line 604 of file loggers.h.

§ warning() [2/3]

template<typename Derived>
template<ENABLED_IF( staticallyEnabledFor< WARNING >()) >
void Tomographer::Logger::LoggerBase< Derived >::warning ( const char *  origin,
std::string  msg 
)
inline

emit a warning message

Call this method to report a warning.

See debug(const char*, std::string) for information about the function arguments.

Definition at line 620 of file loggers.h.

§ warning() [3/3]

template<typename Derived>
template<typename Fn , ENABLED_IF( staticallyEnabledFor< WARNING >() && tomo_internal::IsOstreamArgCallable< Fn >::value) >
void Tomographer::Logger::LoggerBase< Derived >::warning ( const char *  origin,
Fn &&  f 
)
inline

emit a warning message

Call this method to report a warning.

See debug(const char *, Fn&&) for information about the function arguments.

Definition at line 634 of file loggers.h.


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