Tomographer  v1.0a
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...
 
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...
 
template<typename Fn >
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...
 
template<typename Fn >
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...
 
template<typename Fn >
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...
 
template<typename Fn >
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...
 
template<typename Fn >
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...
 
template<typename Fn >
void log (int level, const char *origin, Fn f)
 emit a log message at the given log level. More...
 
template<int Level>
void log (const char *origin, const char *fmt,...)
 emit a log message at the given log level. More...
 
template<int 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>
void log (const char *origin, const std::string &msg)
 emit a log message at the given log level. More...
 
template<int Level, typename Fn >
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...
 

Static Public Member Functions

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

Protected Member Functions

template<bool dummy = true, typename std::enable_if< dummy &&!HasOwnGetLevel, bool >::type dummy2 = true>
int getLevel () const
 
template<bool dummy = true, typename std::enable_if< dummy &&HasOwnGetLevel, bool >::type dummy2 = true>
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 424 of file loggers.h.

Member Enumeration Documentation

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 432 of file loggers.h.

Constructor & Destructor Documentation

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 logger() method, and declares it with LoggerTraits<Derived>::HasOwnGetLevel, then the level provided here is discarded and ignored.

Definition at line 452 of file loggers.h.

Member Function Documentation

template<typename Derived >
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 1062 of file loggers.h.

template<typename Derived >
void Tomographer::Logger::LoggerBase< Derived >::debug ( const char *  origin,
const 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 1071 of file loggers.h.

template<typename Derived >
template<typename Fn >
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 1079 of file loggers.h.

template<typename Derived>
bool Tomographer::Logger::LoggerBase< Derived >::enabled_for ( 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 755 of file loggers.h.

template<typename Derived >
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 992 of file loggers.h.

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

emit an error message

Call this method to report an error.

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

Definition at line 1001 of file loggers.h.

template<typename Derived >
template<typename Fn >
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 1009 of file loggers.h.

template<typename Derived >
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 1039 of file loggers.h.

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

emit an information/notice message

Call this method to report an information/notice message.

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

Definition at line 1048 of file loggers.h.

template<typename Derived >
template<typename Fn >
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 1056 of file loggers.h.

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 777 of file loggers.h.

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 1109 of file loggers.h.

template<typename Derived >
void Tomographer::Logger::LoggerBase< Derived >::log ( int  level,
const char *  origin,
const 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*, const std::string&) for information about the function arguments.

Definition at line 1118 of file loggers.h.

template<typename Derived >
template<typename Fn >
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 1126 of file loggers.h.

template<typename Derived >
template<int 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 1134 of file loggers.h.

template<typename Derived >
template<int 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 1144 of file loggers.h.

template<typename Derived >
template<int Level>
void Tomographer::Logger::LoggerBase< Derived >::log ( const char *  origin,
const 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*, const std::string&) for information about the function arguments.

Definition at line 1151 of file loggers.h.

template<typename Derived >
template<int Level, typename Fn >
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 1159 of file loggers.h.

template<typename Derived >
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 1085 of file loggers.h.

template<typename Derived >
void Tomographer::Logger::LoggerBase< Derived >::longdebug ( const char *  origin,
const 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*, const std::string&) for information about the function arguments.

Definition at line 1094 of file loggers.h.

template<typename Derived >
template<typename Fn >
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 1102 of file loggers.h.

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 828 of file loggers.h.

template<typename Derived>
static bool Tomographer::Logger::LoggerBase< Derived >::statically_enabled_for ( 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 enabled_for()).

Definition at line 728 of file loggers.h.

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

Static version of statically_enabled_for()

Definition at line 737 of file loggers.h.

template<typename Derived >
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 1016 of file loggers.h.

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

emit a warning message

Call this method to report a warning.

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

Definition at line 1025 of file loggers.h.

template<typename Derived >
template<typename Fn >
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 1033 of file loggers.h.


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