22 #ifndef _PFASST__LOGGING_HPP_
23 #define _PFASST__LOGGING_HPP_
37 #include <boost/algorithm/string.hpp>
52 static const string red;
85 #define ELPP_STL_LOGGING
87 #define ELPP_NO_DEFAULT_LOG_FILE
89 #define ELPP_LOGGING_FLAGS_FROM_ARG
92 #define ELPP_DEBUG_ASSERT_FAILURE
93 #define ELPP_STACKTRACE_ON_CRASH
96 #ifdef PFASST_NO_LOGGING
97 #define ELPP_DISABLE_LOGS
101 #include <pfasst/easylogging++.h>
110 #define ML_LOG(level, x) LOG(level) << x
117 #define ML_CLOG(level, logger_id, x) CLOG(level, logger_id) << x
124 #define ML_CLOG_IF(condition, level, logger_id, x) CLOG_IF(condition, level, logger_id) << x
131 #define ML_CVLOG(verbose_level, logger_id, x) CVLOG(verbose_level, logger_id) << x
138 #define ML_CVLOG_IF(condition, verbose_level, logger_id, x) CVLOG_IF(condition, verbose_level, logger_id) << x
140 #define ML_LOG(level, x)
141 #define ML_CLOG(level, logger_id, x)
142 #define ML_CLOG_IF(condition, level, logger_id, x)
143 #define ML_CVLOG(verbose_level, logger_id, x)
144 #define ML_CVLOG_IF(condition, verbose_level, logger_id, x)
149 #ifndef PFASST_LOGGER_INITIALIZED
152 INITIALIZE_EASYLOGGINGPP
163 #define PFASST_LOGGER_INITIALIZED
166 #ifndef PFASST_LOGGER_DEFAULT_GLOBAL_MILLISECOND_WIDTH
167 #define PFASST_LOGGER_DEFAULT_GLOBAL_MILLISECOND_WIDTH "2"
171 #ifndef VLOG_FUNC_START
176 #define VLOG_FUNC_START(scope) \
177 pfasst::log::stack_position++; \
178 VLOG(9) << std::string((pfasst::log::stack_position - 1) * 2, ' ') << "START: " << std::string(scope) << "::" << std::string(__func__) << "()"
181 #ifndef VLOG_FUNC_END
186 #define VLOG_FUNC_END(scope) \
187 pfasst::log::stack_position--; \
188 VLOG(9) << std::string(pfasst::log::stack_position * 2, ' ') << "DONE: " << std::string(scope) << "::" << std::string(__func__) << "()";
191 #ifndef LOG_PRECISION
192 #define LOG_PRECISION 5
201 string(pfasst::log::stack_position * 2, ' ')
210 #define LOGGER_ID_LENGTH 10
265 ostringstream frmter;
287 string log_name = config::get_value<string>(
"log_prefix",
"");
289 if (log_name.size() > 0) {
310 const el::Configurations* default_conf =
nullptr)
312 string milliseconds_width, to_stdout;
314 el::Configurations* default_conf_nc =
const_cast<el::Configurations*
>(default_conf);
315 milliseconds_width = default_conf_nc->get(el::Level::Info,
316 el::ConfigurationType::MillisecondsWidth)->value();
317 to_stdout = default_conf_nc->get(el::Level::Info,
318 el::ConfigurationType::ToStandardOutput)->value();
322 .count(
"quiet")) ?
"false" :
"true";
325 conf->setGlobally(el::ConfigurationType::ToStandardOutput, to_stdout);
363 .count(
"nocolor") ?
false :
true;
365 const string INFO_COLOR = (colorize) ?
OUT::blue :
"";
366 const string DEBG_COLOR = (colorize) ?
"" :
"";
367 const string WARN_COLOR = (colorize) ?
OUT::magenta :
"";
368 const string ERRO_COLOR = (colorize) ?
OUT::red :
"";
370 const string VERB_COLOR = (colorize) ?
OUT::white :
"";
371 const string TIMESTAMP_COLOR = (colorize) ?
OUT::white :
"";
372 const string RESET = (colorize) ?
OUT::reset :
"";
374 const string TIMESTAMP = TIMESTAMP_COLOR +
"%datetime{%H:%m:%s,%g}" + RESET +
" ";
375 const string LEVEL =
"%level";
376 const string VLEVEL =
"VERB%vlevel";
377 const string POSITION =
"%fbase:%line";
378 const string MESSAGE =
"%msg";
382 const string MPI_RANK =
"";
385 const size_t id_length =
id.size();
387 boost::to_upper(id2print);
389 ML_CLOG(DEBUG,
"default",
"initializing custom logger '" <<
id <<
"' as '" << id2print <<
"'");
395 el::Logger* logger = el::Loggers::getLogger(
id);
396 el::Configurations* conf = logger->configurations();
397 const el::Configurations* default_conf = el::Loggers::defaultConfigurations();
400 conf->set(el::Level::Info, el::ConfigurationType::Format,
401 TIMESTAMP + INFO_COLOR +
"[" + id2print +
", " + LEVEL + MPI_RANK +
"] " + MESSAGE + RESET);
402 conf->set(el::Level::Debug, el::ConfigurationType::Format,
403 TIMESTAMP + DEBG_COLOR +
"[" + id2print +
", " + LEVEL + MPI_RANK +
"] " + POSITION +
" " + MESSAGE + RESET);
404 conf->set(el::Level::Warning, el::ConfigurationType::Format,
405 TIMESTAMP + WARN_COLOR +
"[" + id2print +
", " + LEVEL + MPI_RANK +
"] " + MESSAGE + RESET);
406 conf->set(el::Level::Error, el::ConfigurationType::Format,
407 TIMESTAMP + ERRO_COLOR +
"[" + id2print +
", " + LEVEL + MPI_RANK +
"] " + MESSAGE + RESET);
408 conf->set(el::Level::Fatal, el::ConfigurationType::Format,
409 TIMESTAMP + FATA_COLOR +
"[" + id2print +
", " + LEVEL + MPI_RANK +
"] " + POSITION +
" " + MESSAGE + RESET);
410 conf->set(el::Level::Verbose, el::ConfigurationType::Format,
411 TIMESTAMP + VERB_COLOR +
"[" + id2print +
", " + VLEVEL + MPI_RANK +
"] " + MESSAGE + RESET);
412 el::Loggers::reconfigureLogger(logger, *conf);
424 el::Configurations defaultConf;
425 defaultConf.setToDefault();
429 el::Loggers::setDefaultConfigurations(defaultConf,
true);
462 el::Loggers::addFlag(el::LoggingFlag::LogDetailedCrashReason);
463 el::Loggers::addFlag(el::LoggingFlag::DisableApplicationAbortOnFatalLog);
465 el::Loggers::removeFlag(el::LoggingFlag::ColoredTerminalOutput);
467 el::Loggers::addFlag(el::LoggingFlag::ColoredTerminalOutput);
469 el::Loggers::addFlag(el::LoggingFlag::MultiLoggerSupport);
470 el::Loggers::addFlag(el::LoggingFlag::CreateLoggerAutomatically);
489 cout <<
"### Example of different Logging Levels:" << endl;
492 ML_LOG(WARNING,
"warning");
494 ML_LOG(FATAL,
"fatal error");
496 for (
size_t level = 0; level <= 9; ++level) {
497 ML_CVLOG(level,
"default",
"verbosity level " << level);
499 cout <<
"### End Example Logging Levels" << endl << endl;
520 START_EASYLOGGINGPP(argc, argv);
529 #endif // _PFASST__LOGGING_HPP_
string format_mpi_rank(const char fill= ' ')
Formats the local MPI world rank as a string.
static void start_log(int argc, char **argv)
Starts easylogging++ with given arguments and loads configuration.
int get_rank()
Get MPI rank during initialization.
#define LOGGER_ID_LENGTH
Length of logger ID to print.
static const string underline
static const string reset
resets both, colour and style
static size_t stack_position
#define ML_CLOG(level, logger_id, x)
same as CLOG(level, logger, x) from easylogging++
static void add_custom_logger(const string &id)
Provides convenient way of adding additional named loggers.
static const string white
static const string green
static void set_logging_flags()
Sets some default flags for easylogging++.
#define ML_LOG(level, x)
same as LOG(level, x) from easylogging++
po::variables_map & get_variables_map()
static bool initialized
internal flag identifying whether the default logger has been initialized.
static options & get_instance()
Accessor to the singleton instance.
static const string black
static void test_logging_levels()
Prints example logging for all logging levels for the default logger.
static constexpr const char * VERSION
PFASST++ version: closest release tag and a brief git hash.
#define ML_CVLOG(verbose_level, logger_id, x)
same as CVLOG(verbosity, logger, x) from easylogging++
#define PFASST_LOGGER_DEFAULT_GLOBAL_MILLISECOND_WIDTH
precision of milliseconds to be printed
string get_log_file_name()
Composes the log file name for the local rank.
void set_global_logging_options(el::Configurations *conf, const el::Configurations *default_conf=nullptr)
Sets global logging options.
static const string magenta
static const string yellow
Some general variables for coloured terminal output.
static void load_default_config()
Sets default configuration for default loggers.