Provides easy and fast logging functionality.
For more information on the logging, see Logging class.
Definition in file logging.hpp.
#include "genesis/utils/core/std.hpp"
#include <cmath>
#include <iosfwd>
#include <memory>
#include <sstream>
#include <string>
#include <vector>
Go to the source code of this file.
Classes | |
class | Logging |
Logging class with easy and fast usage. More... | |
struct | LoggingDetails |
POD stuct containing the settings for which information is included with each logging message. More... | |
class | LoggingScopeLevel |
Class that sets the Logging Level to a value von construction and set it back on destruction. This is used by the log scope level macro. More... | |
Namespaces | |
genesis | |
Container namespace for all symbols of genesis in order to keep them separate when used as a library. | |
genesis::utils | |
Macros | |
#define | GENESIS_LOG(level) |
#define | GENESIS_LOG_DETAILS(level, ...) |
#define | LOG_BOLD |
Logging of a message that is always displayed. More... | |
#define | LOG_DBG GENESIS_LOG(genesis::utils::Logging::kDebug) |
Log a debug message. See genesis::utils::LoggingLevel. More... | |
#define | LOG_DBG1 GENESIS_LOG(genesis::utils::Logging::kDebug1) |
Log a debug message. See genesis::utils::LoggingLevel. More... | |
#define | LOG_DBG2 GENESIS_LOG(genesis::utils::Logging::kDebug2) |
Log a debug message. See genesis::utils::LoggingLevel. More... | |
#define | LOG_DBG3 GENESIS_LOG(genesis::utils::Logging::kDebug3) |
Log a debug message. See genesis::utils::LoggingLevel. More... | |
#define | LOG_DBG4 GENESIS_LOG(genesis::utils::Logging::kDebug4) |
Log a debug message. See genesis::utils::LoggingLevel. More... | |
#define | LOG_ERR GENESIS_LOG(genesis::utils::Logging::kError) |
Log an error. See genesis::utils::LoggingLevel. More... | |
#define | LOG_INFO GENESIS_LOG(genesis::utils::Logging::kInfo) |
Log an info message. See genesis::utils::LoggingLevel. More... | |
#define | LOG_LEVEL_MAX genesis::utils::Logging::kDebug4 |
Static maximal logging level. More... | |
#define | LOG_MSG GENESIS_LOG(genesis::utils::Logging::kMessage) |
Log an info message. See genesis::utils::LoggingLevel. More... | |
#define | LOG_MSG1 GENESIS_LOG(genesis::utils::Logging::kMessage1) |
Log an info message. See genesis::utils::LoggingLevel. More... | |
#define | LOG_MSG2 GENESIS_LOG(genesis::utils::Logging::kMessage2) |
Log an info message. See genesis::utils::LoggingLevel. More... | |
#define | LOG_MSG3 GENESIS_LOG(genesis::utils::Logging::kMessage3) |
Log an info message. See genesis::utils::LoggingLevel. More... | |
#define | LOG_MSG4 GENESIS_LOG(genesis::utils::Logging::kMessage4) |
Log an info message. See genesis::utils::LoggingLevel. More... | |
#define | LOG_PROG(value, quantity) |
Logging of a progress message. More... | |
#define | LOG_SCOPE_LEVEL(level) genesis::utils::LoggingScopeLevel genesis_logging_scope_level_temp_object(level); |
This macro sets the logging level to a certain value for this scope and sets it back to the original value on exiting the scope. More... | |
#define | LOG_TIME |
Logging of a message with timing information. More... | |
#define | LOG_WARN GENESIS_LOG(genesis::utils::Logging::kWarning) |
Log a warning. See genesis::utils::LoggingLevel. More... | |
Functions | |
long | logging_progress_value (long value=-1) |
Hack function to make sure that the value arugment in LOG_PROG is only evaluated once. More... | |
#define GENESIS_LOG | ( | level | ) |
Definition at line 80 of file logging.hpp.
#define GENESIS_LOG_DETAILS | ( | level, | |
... | |||
) |
Definition at line 86 of file logging.hpp.
#define LOG_BOLD |
Logging of a message that is always displayed.
It does not include any details with its message stream (thus, is independent of Logging::details) and is always logged (independent of the max levels). This is for example used to log the program header and footer on startup and termination.
Definition at line 143 of file logging.hpp.
#define LOG_DBG GENESIS_LOG(genesis::utils::Logging::kDebug) |
Log a debug message. See genesis::utils::LoggingLevel.
Definition at line 118 of file logging.hpp.
#define LOG_DBG1 GENESIS_LOG(genesis::utils::Logging::kDebug1) |
Log a debug message. See genesis::utils::LoggingLevel.
Definition at line 121 of file logging.hpp.
#define LOG_DBG2 GENESIS_LOG(genesis::utils::Logging::kDebug2) |
Log a debug message. See genesis::utils::LoggingLevel.
Definition at line 124 of file logging.hpp.
#define LOG_DBG3 GENESIS_LOG(genesis::utils::Logging::kDebug3) |
Log a debug message. See genesis::utils::LoggingLevel.
Definition at line 127 of file logging.hpp.
#define LOG_DBG4 GENESIS_LOG(genesis::utils::Logging::kDebug4) |
Log a debug message. See genesis::utils::LoggingLevel.
Definition at line 130 of file logging.hpp.
#define LOG_ERR GENESIS_LOG(genesis::utils::Logging::kError) |
Log an error. See genesis::utils::LoggingLevel.
Definition at line 94 of file logging.hpp.
#define LOG_INFO GENESIS_LOG(genesis::utils::Logging::kInfo) |
Log an info message. See genesis::utils::LoggingLevel.
Definition at line 100 of file logging.hpp.
#define LOG_LEVEL_MAX genesis::utils::Logging::kDebug4 |
Static maximal logging level.
Everything above this level will be pruned by the compiler.
Definition at line 66 of file logging.hpp.
#define LOG_MSG GENESIS_LOG(genesis::utils::Logging::kMessage) |
Log an info message. See genesis::utils::LoggingLevel.
Definition at line 103 of file logging.hpp.
#define LOG_MSG1 GENESIS_LOG(genesis::utils::Logging::kMessage1) |
Log an info message. See genesis::utils::LoggingLevel.
Definition at line 106 of file logging.hpp.
#define LOG_MSG2 GENESIS_LOG(genesis::utils::Logging::kMessage2) |
Log an info message. See genesis::utils::LoggingLevel.
Definition at line 109 of file logging.hpp.
#define LOG_MSG3 GENESIS_LOG(genesis::utils::Logging::kMessage3) |
Log an info message. See genesis::utils::LoggingLevel.
Definition at line 112 of file logging.hpp.
#define LOG_MSG4 GENESIS_LOG(genesis::utils::Logging::kMessage4) |
Log an info message. See genesis::utils::LoggingLevel.
Definition at line 115 of file logging.hpp.
#define LOG_PROG | ( | value, | |
quantity | |||
) |
Logging of a progress message.
This special logging mechanism provides an easy way to report progress while running long operations. It uses LoggingLevel::kProgress for its messages.
It takes two arguments, the first one being the number of the current iteration of the loop, the second the total number of iterations, both are casted to long.
The integer value of Logging::report_percentage can be used to control how often progress is reported in terms of a percentage counter. Default is 5, meaning every 5% progress is reported.
The trailing message is optional – when left out, simply the percentage number will be logged. However, the statement must always be ended by a semicolon.
The default use case looks like this:
Logging::report_percentage(2); for (int i = 0; i < n; ++i) { // long loop from 0 to n // do stuff... LOG_PROG(i, n) << "of the loop finished."; }
This will report the progress of the loop every 2 percent with a message like this:
0% of the loop finished. 2% of the loop finished. 4% of the loop finished. ...
It is also possible to increment the iteration counter inline:
LOG_PROG(++i, n) << "of stuff finished.";
It automatically checks whether it is time to report, so that the user does not have to take care of this.
Caveat: For small number of iterations (<100) it is not entirely accurate. Because of the involved integer modulo calculations, it will trigger too many messages. However, as this type of logging is usually used for loops with many iterations, this should rarely be an issue.
There is a slight overhead of ~60ms per 1mio invocations because of the needed calculations.
Definition at line 232 of file logging.hpp.
#define LOG_SCOPE_LEVEL | ( | level | ) | genesis::utils::LoggingScopeLevel genesis_logging_scope_level_temp_object(level); |
This macro sets the logging level to a certain value for this scope and sets it back to the original value on exiting the scope.
This is useful to disable debug messages in a function while still beging able to activate them when needed. The macro creates class instance of LoggingScopeLevel with a long and hopefully unique name.
Definition at line 165 of file logging.hpp.
#define LOG_TIME |
Logging of a message with timing information.
It includes the run time difference to the last log message in seconds as its only detail (independent of Logging::details). This is particularly useful for timing and profiling code sections. Its level is Logging::kDebug, so that in can be easily turned of for production code.
Definition at line 154 of file logging.hpp.
#define LOG_WARN GENESIS_LOG(genesis::utils::Logging::kWarning) |
Log a warning. See genesis::utils::LoggingLevel.
Definition at line 97 of file logging.hpp.