|
A library for working with phylogenetic and population genetic data.
v0.27.0
|
|
Go to the documentation of this file.
39 #if defined(GENESIS_PTHREADS) || defined(GENESIS_OPENMP)
55 #if defined(GENESIS_PTHREADS) || defined(GENESIS_OPENMP)
91 throw std::runtime_error(
92 "Logging max level set to " +
std::to_string( level ) +
", but compile time max level is " +
104 if (percentage <= 0) {
105 throw std::runtime_error(
"Logging report percentage less than 1% not possible." );
107 if (percentage > 100) {
108 throw std::runtime_error(
"Logging report percentage greater than 100% not meaningful." );
118 static const char*
const buffer[] = {
119 "NONE",
"ERR ",
"WARN",
"INFO",
"PROG",
120 "MSG ",
"MSG1",
"MSG2",
"MSG3",
"MSG4",
121 "DBG ",
"DBG1",
"DBG2",
"DBG3",
"DBG4"
123 return buffer[level];
133 if (os == &std::cout) {
163 fstreams_.push_back( genesis::utils::make_unique<std::ofstream>());
187 clock_t now_clock = clock();
188 std::ostringstream det_buff;
193 det_buff <<
count_ <<
" ";
202 det_buff << std::fixed
203 << std::setprecision(6)
204 << double(now_clock) / CLOCKS_PER_SEC
210 val = (double) (now_clock -
last_clock_) / CLOCKS_PER_SEC;
212 det_buff << std::fixed
213 << std::setprecision(6)
222 det_buff <<
":" <<
line_ <<
" ";
240 std::string msg = det_buff.str();
241 if (msg.length() > 0) {
243 buff_.str(),
"\n",
"\n" + std::string(msg.length(),
' ')
251 # if defined(GENESIS_PTHREADS) || defined(GENESIS_OPENMP)
256 (*out) << msg << std::endl << std::flush;
259 (*out) << msg << std::endl << std::flush;
262 # if defined(GENESIS_PTHREADS) || defined(GENESIS_OPENMP)
280 const std::string& file,
const int line,
const std::string&
function,
284 return get(file, line,
function, level,
details);
295 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.
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.
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.
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::mutex log_mutex
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.
void file_output_stream(std::string const &filename, 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.