|
A library for working with phylogenetic and population genetic data.
v0.32.0
|
|
Go to the documentation of this file.
88 throw std::runtime_error(
89 "Logging max level set to " +
std::to_string( level ) +
", but compile time max level is " +
101 if (percentage <= 0) {
102 throw std::runtime_error(
"Logging report percentage less than 1% not possible." );
104 if (percentage > 100) {
105 throw std::runtime_error(
"Logging report percentage greater than 100% not meaningful." );
115 static const char*
const buffer[] = {
116 "NONE",
"ERR ",
"WARN",
"INFO",
"PROG",
117 "MSG ",
"MSG1",
"MSG2",
"MSG3",
"MSG4",
118 "DBG ",
"DBG1",
"DBG2",
"DBG3",
"DBG4"
120 return buffer[level];
130 if (os == &std::cout) {
160 fstreams_.push_back( genesis::utils::make_unique<std::ofstream>());
184 clock_t now_clock = clock();
185 std::ostringstream det_buff;
190 det_buff <<
count_ <<
" ";
199 det_buff << std::fixed
200 << std::setprecision(6)
201 << double(now_clock) / CLOCKS_PER_SEC
207 val = (double) (now_clock -
last_clock_) / CLOCKS_PER_SEC;
209 det_buff << std::fixed
210 << std::setprecision(6)
219 det_buff <<
":" <<
line_ <<
" ";
237 std::string msg = det_buff.str();
238 if (msg.length() > 0) {
240 buff_.str(),
"\n",
"\n" + std::string(msg.length(),
' ')
250 (*out) << msg << std::endl << std::flush;
253 (*out) << msg << std::endl << std::flush;
270 const std::string& file,
const int line,
const std::string&
function,
274 return get(file, line,
function, level,
details);
285 const std::string& file,
const int line,
const std::string&
function,
POD stuct containing the settings for which information is included with each logging message.
#define LOG_LEVEL_MAX
Static maximal logging level.
static std::vector< std::unique_ptr< std::ofstream > > fstreams_
std::string trim_right(std::string const &s, std::string const &delimiters)
Return a copy of the input string, with left trimmed white spaces (or any other delimiters).
static int report_percentage_
~Logging()
Destructor that is invoked at the end of each log line and does the actual output.
std::string current_date()
Returns the current date as a string in the format "2014-12-31".
bool date
Include the current date.
std::string replace_all(std::string const &text, std::string const &search, std::string const &replace)
Return a copy of a string, where all occurrences of a search string are replaced by a replace string.
Provides functions for date and time access.
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.
static std::vector< std::ostream * > ostreams_
static void clear()
Remove all output streams, so that nothing is logged any more.
bool count
Include a counter of how many messages have been logged so far.
bool level
Include the level (e.g. Info, Debug) of the message.
static clock_t last_clock_
bool file
Include the filename where the log message was generated.
Provides some valuable additions to STD.
std::string current_time()
Returns the current time as a string in the format "13:37:42".
static LoggingDetails details
Settings for which information is included with each log message. See LoggingDetails for usage.
bool function
Include the function name where the log message was generated.
std::string to_string(GenomeLocus const &locus)
Provides some commonly used string utility functions.
LoggingLevel
Levels of severity used for logging.
static LoggingLevel max_level()
Get the highest log level that is reported.
Provides easy and fast logging functionality.
static std::string level_to_string(const LoggingLevel level)
Return a string representation of a log level.
void file_output_stream(std::string const &file_name, std::ofstream &out_stream, std::ios_base::openmode mode=std::ios_base::out, bool create_dirs=true)
Helper function to obtain an output stream to a file.
static int report_percentage()
Get the current percentage for reporting LOG_PROG messages.
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
bool line
Include the line of the file where the log message was generated.
bool runtime
Include the current run time of the program in sec.
static void log_to_file(const std::string &fn)
Add an output file to which log messages are written.
static void log_to_stream(std::ostream &os)
Add an output stream to which log messages are written.
static std::mutex genesis_log_mutex_
bool time
Include the current time.
static LoggingLevel max_level_
static void log_to_stdout()
Add stdout as output stream to which log messages are written.
@ kDebug
Basic debugging message. See LOG_DBG.
static std::string debug_indent
Indention string for Debug Levels 1-4.
bool rundiff
Include the run time difference to the last log message in sec.