A toolkit for working with phylogenetic data.
v0.19.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
logging.hpp File Reference

Detailed Description

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 <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_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...
 

Macro Definition Documentation

#define GENESIS_LOG (   level)
Value:
if (level > LOG_LEVEL_MAX) ; \
else if (level > genesis::utils::Logging::max_level()) ; \
else genesis::utils::Logging().get(__FILE__, __LINE__, GENESIS_FUNC, level)
std::ostringstream & get(const std::string &file, const int line, const std::string &function, const LoggingLevel level)
Getter for the singleton instance of log, is called by the standard macros.
Definition: logging.cpp:263
Logging class with easy and fast usage.
Definition: logging.hpp:351
static LoggingLevel max_level()
Get the highest log level that is reported.
Definition: logging.hpp:440
#define LOG_LEVEL_MAX
Static maximal logging level.
Definition: logging.hpp:64
#define GENESIS_FUNC
Definition: std.hpp:52

Definition at line 78 of file logging.hpp.

#define GENESIS_LOG_DETAILS (   level,
  ... 
)
Value:
if (level > LOG_LEVEL_MAX) ; \
else if (level > genesis::utils::Logging::max_level()) ; \
else genesis::utils::Logging().get(__FILE__, __LINE__, GENESIS_FUNC, level, {__VA_ARGS__})
std::ostringstream & get(const std::string &file, const int line, const std::string &function, const LoggingLevel level)
Getter for the singleton instance of log, is called by the standard macros.
Definition: logging.cpp:263
Logging class with easy and fast usage.
Definition: logging.hpp:351
static LoggingLevel max_level()
Get the highest log level that is reported.
Definition: logging.hpp:440
#define LOG_LEVEL_MAX
Static maximal logging level.
Definition: logging.hpp:64
#define GENESIS_FUNC
Definition: std.hpp:52

Definition at line 84 of file logging.hpp.

#define LOG_BOLD
Value:
false, false, false, false, false, false, false, false, false)
Special messages that are always logged, e.g. program header.
Definition: logging.hpp:372
#define GENESIS_LOG_DETAILS(level,...)
Definition: logging.hpp:84

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 126 of file logging.hpp.

Log a debug message. See genesis::utils::LoggingLevel.

Definition at line 101 of file logging.hpp.

Log a debug message. See genesis::utils::LoggingLevel.

Definition at line 104 of file logging.hpp.

Log a debug message. See genesis::utils::LoggingLevel.

Definition at line 107 of file logging.hpp.

Log a debug message. See genesis::utils::LoggingLevel.

Definition at line 110 of file logging.hpp.

Log a debug message. See genesis::utils::LoggingLevel.

Definition at line 113 of file logging.hpp.

Log an error. See genesis::utils::LoggingLevel.

Definition at line 92 of file logging.hpp.

Log an info message. See genesis::utils::LoggingLevel.

Definition at line 98 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 64 of file logging.hpp.

#define LOG_PROG (   value,
  quantity 
)
Value:
else if( (long) genesis::utils::logging_progress_value(value) % \
(((long) (quantity) * genesis::utils::Logging::report_percentage() / 100) > 0 ? \
((long) (quantity) * genesis::utils::Logging::report_percentage() / 100) : 1) != 0 ) ; \
(int) round(100.0 * (double) genesis::utils::logging_progress_value() / ((quantity) > 0 ? (quantity) : 1)) << "% "
std::ostringstream & get(const std::string &file, const int line, const std::string &function, const LoggingLevel level)
Getter for the singleton instance of log, is called by the standard macros.
Definition: logging.cpp:263
Logging class with easy and fast usage.
Definition: logging.hpp:351
static LoggingLevel max_level()
Get the highest log level that is reported.
Definition: logging.hpp:440
#define LOG_LEVEL_MAX
Static maximal logging level.
Definition: logging.hpp:64
static int report_percentage()
Get the current percentage for reporting LOG_PROG messages.
Definition: logging.hpp:447
long logging_progress_value(long value=-1)
Hack function to make sure that the value arugment in LOG_PROG is only evaluated once.
Definition: logging.hpp:162
Progess, used in long executing functions. See LOG_PROG.
Definition: logging.hpp:384
#define GENESIS_FUNC
Definition: std.hpp:52

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 215 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 148 of file logging.hpp.

#define LOG_TIME
Value:
false, false, false, false , true, false, false, false, false)
#define GENESIS_LOG_DETAILS(level,...)
Definition: logging.hpp:84
Basic debugging message. See LOG_DBG.
Definition: logging.hpp:387

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 137 of file logging.hpp.

Log a warning. See genesis::utils::LoggingLevel.

Definition at line 95 of file logging.hpp.