From 35c64c67a2879507603e84bb039a8ec5554b7ceb Mon Sep 17 00:00:00 2001 From: NicolasWinckler Date: Fri, 20 Nov 2015 15:25:34 +0100 Subject: [PATCH] add a command line to enable/disable the color format in the fairmq log console output --- fairmq/logger/logger.cxx | 5 +++-- fairmq/logger/logger_def.h | 1 + fairmq/options/FairMQProgOptions.cxx | 3 +++ fairmq/options/FairProgOptions.cxx | 1 + fairmq/options/FairProgOptionsHelper.h | 9 ++++++++- 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/fairmq/logger/logger.cxx b/fairmq/logger/logger.cxx index 2bfbd24c..7a696878 100644 --- a/fairmq/logger/logger.cxx +++ b/fairmq/logger/logger.cxx @@ -49,7 +49,7 @@ void init_log_console(bool color_format) { // add a text sink typedef sinks::synchronous_sink text_sink; - + logging::core::get()->remove_all_sinks(); // CONSOLE - all severity except error boost::shared_ptr sink = boost::make_shared(); @@ -62,7 +62,7 @@ void init_log_console(bool color_format) else sink->set_formatter(&init_log_formatter); - sink->set_filter(severity != SEVERITY_ERROR); + sink->set_filter(severity != SEVERITY_ERROR && severity < SEVERITY_NOLOG); // add sink to the core logging::core::get()->add_sink(sink); @@ -82,6 +82,7 @@ void init_log_console(bool color_format) void reinit_logger(bool color_format) { + LOG(NOLOG)<<""; logging::core::get()->remove_all_sinks(); init_log_console(color_format); } diff --git a/fairmq/logger/logger_def.h b/fairmq/logger/logger_def.h index c0fb3d69..34dd5ed5 100644 --- a/fairmq/logger/logger_def.h +++ b/fairmq/logger/logger_def.h @@ -88,6 +88,7 @@ inline std::string write_in(const std::string& text_in_bold) typedef fairmq::severity_level custom_severity_level; #define SEVERITY_THRESHOLD custom_severity_level::TRACE #define SEVERITY_ERROR custom_severity_level::ERROR +#define SEVERITY_NOLOG custom_severity_level::NOLOG // tags used for log console or file formatting struct tag_console; diff --git a/fairmq/options/FairMQProgOptions.cxx b/fairmq/options/FairMQProgOptions.cxx index 58b0f932..4c68f810 100644 --- a/fairmq/options/FairMQProgOptions.cxx +++ b/fairmq/options/FairMQProgOptions.cxx @@ -61,6 +61,9 @@ int FairMQProgOptions::ParseAll(const int argc, char** argv, bool allowUnregiste // set log level before printing (default is 0 = DEBUG level) std::string verbose=GetValue("verbose"); + bool color_format=GetValue("log-color-format"); + if(!color_format) + reinit_logger(false); //SET_LOG_LEVEL(DEBUG); if (fSeverityMap.count(verbose)) { diff --git a/fairmq/options/FairProgOptions.cxx b/fairmq/options/FairProgOptions.cxx index 02fa0692..f768d71e 100644 --- a/fairmq/options/FairProgOptions.cxx +++ b/fairmq/options/FairProgOptions.cxx @@ -42,6 +42,7 @@ FairProgOptions::FairProgOptions() : " STATE \n" " NOLOG" ) + ("log-color-format", po::value()->default_value(true), "logger color format : true or false") ; fSeverityMap["TRACE"] = fairmq::severity_level::TRACE; diff --git a/fairmq/options/FairProgOptionsHelper.h b/fairmq/options/FairProgOptionsHelper.h index 4acd7a72..e737130e 100644 --- a/fairmq/options/FairProgOptionsHelper.h +++ b/fairmq/options/FairProgOptionsHelper.h @@ -210,10 +210,17 @@ namespace fairmq if (is_this_type(varValue)) return T::template Value(varValue,std::string(" [Type=std::size_t]"),defaultedValue,emptyValue); - // std::vector short + // std::vector size_t if (is_this_type>(varValue)) return T::template Value>(varValue,std::string(" [Type=vector]"),defaultedValue,emptyValue); + // bool + if (is_this_type(varValue)) + return T::template Value(varValue,std::string(" [Type=bool]"),defaultedValue,emptyValue); + + // std::vector bool + if (is_this_type>(varValue)) + return T::template Value>(varValue,std::string(" [Type=vector]"),defaultedValue,emptyValue); //////////////////////////////// boost types // boost::filesystem::path