Tomographer
v1.0a
Tomographer C++ Framework Documentation
|
Base logger class. More...
#include <tomographer/tools/loggers.h>
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... | |
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).
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. |
|
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.
|
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.
origin | A 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()" ). |
fmt | A printf format string |
... | additional arguments for the printf formatting string. |
|
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.
origin | A 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()" ). |
msg | the log message to produce. |
|
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:
origin | A 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()" ). |
f | a 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!)
|
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()).
|
inline |
|
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.
|
inline |
emit an error message
Call this method to report an error.
See debug(const char *, Fn) for information about the function arguments.
|
inline |
|
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.
|
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.
|
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!
|
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.
|
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.
|
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.
|
inline |
|
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, ...) .
|
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.
|
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.
|
inline |
|
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.
|
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.
|
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.)
|
inlinestatic |
Check whether the logger is statically disabled for some levels.
Level | the log level to test for. |
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()).
|
inlinestatic |
Static version of statically_enabled_for()
|
inline |
|
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.
|
inline |
emit a warning message
Call this method to report a warning.
See debug(const char *, Fn) for information about the function arguments.