From e0ca1f62b350e1e0fffc70913bd3604b1b568f55 Mon Sep 17 00:00:00 2001 From: winckler Date: Mon, 7 Sep 2015 18:51:50 +0200 Subject: [PATCH] - Replace the fairmq logger with one based on Boost.Log - Adapt FairProgOptions to the new logger --- fairmq/CMakeLists.txt | 5 +- fairmq/FairMQLogger.cxx | 68 +------- fairmq/FairMQLogger.h | 41 +---- fairmq/FairMQTransportFactory.h | 1 - fairmq/logger/CMakeLists.txt | 43 +++++ fairmq/logger/logger.cxx | 234 +++++++++++++++++++++++++++ fairmq/logger/logger.h | 129 +++++++++++++++ fairmq/logger/logger_def.h | 183 +++++++++++++++++++++ fairmq/logger/run/testLogger.cxx | 66 ++++++++ fairmq/options/FairMQParser.cxx | 30 ++-- fairmq/options/FairMQProgOptions.cxx | 13 +- fairmq/options/FairMQProgOptions.h | 2 +- fairmq/options/FairProgOptions.cxx | 47 ++++-- fairmq/options/FairProgOptions.h | 5 +- 14 files changed, 722 insertions(+), 145 deletions(-) create mode 100644 fairmq/logger/CMakeLists.txt create mode 100644 fairmq/logger/logger.cxx create mode 100644 fairmq/logger/logger.h create mode 100644 fairmq/logger/logger_def.h create mode 100644 fairmq/logger/run/testLogger.cxx diff --git a/fairmq/CMakeLists.txt b/fairmq/CMakeLists.txt index 6f602994..bcbe82aa 100644 --- a/fairmq/CMakeLists.txt +++ b/fairmq/CMakeLists.txt @@ -9,12 +9,13 @@ configure_file(${CMAKE_SOURCE_DIR}/fairmq/options/ProgOptionTest/macro/bsampler-sink.json ${CMAKE_BINARY_DIR}/bin/config/bsampler-sink.json) configure_file(${CMAKE_SOURCE_DIR}/fairmq/examples/1-sampler-sink/sampler-sink.json ${CMAKE_BINARY_DIR}/bin/config/ex1-sampler-sink.json) configure_file(${CMAKE_SOURCE_DIR}/fairmq/examples/2-sampler-processor-sink/sampler-processor-sink.json ${CMAKE_BINARY_DIR}/bin/config/ex2-sampler-processor-sink.json) - +add_subdirectory(logger) Set(INCLUDE_DIRECTORIES ${CMAKE_SOURCE_DIR}/fairmq ${CMAKE_SOURCE_DIR}/fairmq/devices ${CMAKE_SOURCE_DIR}/fairmq/tools ${CMAKE_SOURCE_DIR}/fairmq/options + ${CMAKE_SOURCE_DIR}/fairmq/logger ${CMAKE_SOURCE_DIR}/fairmq/examples/1-sampler-sink ${CMAKE_SOURCE_DIR}/fairmq/examples/2-sampler-processor-sink ${CMAKE_SOURCE_DIR}/fairmq/examples/req-rep @@ -164,7 +165,7 @@ Set(FAIRMQHEADERS install(FILES ${FAIRMQHEADERS} DESTINATION include) set(DEPENDENCIES - ${DEPENDENCIES} + ${DEPENDENCIES} fairmq_logger boost_thread boost_timer boost_system boost_filesystem boost_program_options boost_random boost_chrono boost_exception ) diff --git a/fairmq/FairMQLogger.cxx b/fairmq/FairMQLogger.cxx index 522c3562..5a8cc71d 100644 --- a/fairmq/FairMQLogger.cxx +++ b/fairmq/FairMQLogger.cxx @@ -12,74 +12,10 @@ * @author D. Klein, A. Rybalchenko */ +#include +#include #include "FairMQLogger.h" - -int FairMQLogger::fMinLogLevel = FairMQLogger::DEBUG; - -FairMQLogger::FairMQLogger() - : os() - , fLogLevel(DEBUG) -{ -} - -FairMQLogger::~FairMQLogger() -{ - if (fLogLevel >= FairMQLogger::fMinLogLevel && fLogLevel < FairMQLogger::NOLOG) - { - std::cout << os.str() << std::endl; - } -} - -std::ostringstream& FairMQLogger::Log(int type) -{ - std::string type_str; - fLogLevel = type; - switch (type) - { - case DEBUG : - type_str = "\033[01;34mDEBUG\033[0m"; - break; - - case INFO : - type_str = "\033[01;32mINFO\033[0m"; - break; - - case WARN : - type_str = "\033[01;33mWARN\033[0m"; - break; - - case ERROR : - type_str = "\033[01;31mERROR\033[0m"; - break; - - case STATE : - type_str = "\033[01;35mSTATE\033[0m"; - break; - - case NOLOG : - type_str = "\033[01;31mNOLOG\033[0m"; - break; - - default: - break; - } - - timestamp_t tm = get_timestamp(); - timestamp_t ms = tm / 1000.0L; - timestamp_t s = ms / 1000.0L; - time_t t = s; - // size_t fractional_seconds = ms % 1000; - char mbstr[100]; - strftime(mbstr, 100, "%H:%M:%S", localtime(&t)); - - os << "[\033[01;36m" << mbstr << "\033[0m]" - << "[" << type_str << "]" - << " "; - - return os; -} - timestamp_t get_timestamp() { struct timeval now; diff --git a/fairmq/FairMQLogger.h b/fairmq/FairMQLogger.h index 1b7dedb0..5fece131 100644 --- a/fairmq/FairMQLogger.h +++ b/fairmq/FairMQLogger.h @@ -15,49 +15,10 @@ #ifndef FAIRMQLOGGER_H_ #define FAIRMQLOGGER_H_ -#include -#include -#include -#include -#include -#include -#include - -class FairMQLogger -{ - public: - enum Level - { - DEBUG, - INFO, - WARN, - ERROR, - STATE, - NOLOG - }; - - FairMQLogger(); - virtual ~FairMQLogger(); - std::ostringstream& Log(int type); - - static void SetLogLevel(int logLevel) - { - FairMQLogger::fMinLogLevel = logLevel; - } - - private: - std::ostringstream os; - int fLogLevel; - static int fMinLogLevel; -}; +#include "logger/logger.h" typedef unsigned long long timestamp_t; timestamp_t get_timestamp(); -#define LOG(type) FairMQLogger().Log(FairMQLogger::type) -#define MQLOG(type) FairMQLogger().Log(FairMQLogger::type) -#define SET_LOG_LEVEL(loglevel) FairMQLogger::SetLogLevel(FairMQLogger::loglevel) -#define SET_LOGGER_LEVEL(loglevel) FairMQLogger::SetLogLevel(loglevel) - #endif /* FAIRMQLOGGER_H_ */ diff --git a/fairmq/FairMQTransportFactory.h b/fairmq/FairMQTransportFactory.h index 71032e6b..897887d1 100644 --- a/fairmq/FairMQTransportFactory.h +++ b/fairmq/FairMQTransportFactory.h @@ -15,7 +15,6 @@ #ifndef FAIRMQTRANSPORTFACTORY_H_ #define FAIRMQTRANSPORTFACTORY_H_ - #include "FairMQMessage.h" #include "FairMQChannel.h" #include "FairMQSocket.h" diff --git a/fairmq/logger/CMakeLists.txt b/fairmq/logger/CMakeLists.txt new file mode 100644 index 00000000..70bb432b --- /dev/null +++ b/fairmq/logger/CMakeLists.txt @@ -0,0 +1,43 @@ + ################################################################################ + # Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH # + # # + # This software is distributed under the terms of the # + # GNU Lesser General Public Licence version 3 (LGPL) version 3, # + # copied verbatim in the file "LICENSE" # + ################################################################################ +# Create a library + +set(INCLUDE_DIRECTORIES + ${CMAKE_SOURCE_DIR}/fairmq/logger + ${CMAKE_SOURCE_DIR}/fairmq/logger/run + ) + +include_directories(${INCLUDE_DIRECTORIES}) +include_directories(${Boost_INCLUDE_DIRS}) + +set(LINK_DIRECTORIES ${Boost_LIBRARY_DIRS}) + +link_directories(${LINK_DIRECTORIES}) + +set(SRCS logger.cxx) + +set(LIBRARY_NAME fairmq_logger) + +set(DEPENDENCIES + boost_log + boost_log_setup + boost_thread + boost_date_time + boost_filesystem + boost_system + pthread + ) + +GENERATE_LIBRARY() + +# generate test executable +set(EXE_NAME runtestLogger) +set(SRCS run/testLogger.cxx) +set(DEPENDENCIES fairmq_logger) +GENERATE_EXECUTABLE() + diff --git a/fairmq/logger/logger.cxx b/fairmq/logger/logger.cxx new file mode 100644 index 00000000..7d1fea7c --- /dev/null +++ b/fairmq/logger/logger.cxx @@ -0,0 +1,234 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence version 3 (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +#include "logger.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + + +namespace logging = boost::log; +namespace src = boost::log::sources; +namespace expr = boost::log::expressions; +namespace sinks = boost::log::sinks; +namespace attrs = boost::log::attributes; + + + +BOOST_LOG_GLOBAL_LOGGER_INIT(global_logger, src::severity_logger_mt) +{ + src::severity_logger_mt global_logger; + global_logger.add_attribute("TimeStamp", attrs::local_clock()); + init_log_console(); + return global_logger; +} + +void init_log_console() +{ + // add a text sink + typedef sinks::synchronous_sink text_sink; + boost::shared_ptr sink = boost::make_shared(); + // add "console" output stream to our sink + sink->locked_backend()->add_stream(boost::shared_ptr(&std::clog, boost::null_deleter())); + // specify the format of the log message + sink->set_formatter(&init_log_formatter); + // add sink to the core + logging::core::get()->add_sink(sink); +} + +void init_log_file(const std::string& filename, custom_severity_level threshold, log_op::operation op, const std::string& id) +{ + // add a text sink + std::string formatted_filename(filename); + formatted_filename+=id; + formatted_filename+="_%Y-%m-%d_%H-%M-%S.%N.log"; + boost::shared_ptr< sinks::text_file_backend > backend = + boost::make_shared< sinks::text_file_backend > + ( + boost::log::keywords::file_name = formatted_filename, + boost::log::keywords::rotation_size = 10 * 1024 * 1024, + // rotate at midnight every day + boost::log::keywords::time_based_rotation = sinks::file::rotation_at_time_point(0, 0, 0), + // log collector, + // -- maximum total size of the stored log files is 1GB. + // -- minimum free space on the drive is 2GB + boost::log::keywords::max_size = 1000 * 1024 * 1024, + boost::log::keywords::min_free_space = 2000 * 1024 * 1024, + boost::log::keywords::auto_flush = true + //keywords::time_based_rotation = &is_it_time_to_rotate + ); + typedef sinks::synchronous_sink< sinks::text_file_backend > sink_t; + boost::shared_ptr< sink_t > sink(new sink_t(backend)); + + // specify the format of the log message + sink->set_formatter(&init_log_formatter); + + switch (op) + { + case log_op::operation::EQUAL : + sink->set_filter(severity == threshold); + break; + + case log_op::operation::GREATER_THAN : + sink->set_filter(severity > threshold); + break; + + case log_op::operation::GREATER_EQ_THAN : + sink->set_filter(severity >= threshold); + break; + + case log_op::operation::LESS_THAN : + sink->set_filter(severity < threshold); + break; + + case log_op::operation::LESS_EQ_THAN : + sink->set_filter(severity <= threshold); + break; + + default: + break; + } + logging::core::get()->add_sink(sink); +} + +// temporary : to be replaced with c++11 lambda +void set_global_log_level(log_op::operation op, custom_severity_level threshold ) +{ + switch (threshold) + { + case custom_severity_level::TRACE : + set_global_log_level_operation(op,custom_severity_level::TRACE); + break; + + case custom_severity_level::DEBUG : + set_global_log_level_operation(op,custom_severity_level::DEBUG); + break; + + case custom_severity_level::RESULTS : + set_global_log_level_operation(op,custom_severity_level::RESULTS); + break; + + case custom_severity_level::INFO : + set_global_log_level_operation(op,custom_severity_level::INFO); + break; + + case custom_severity_level::WARN : + set_global_log_level_operation(op,custom_severity_level::WARN); + break; + + case custom_severity_level::STATE : + set_global_log_level_operation(op,custom_severity_level::STATE); + break; + + case custom_severity_level::ERROR : + set_global_log_level_operation(op,custom_severity_level::ERROR); + break; + + case custom_severity_level::NOLOG : + set_global_log_level_operation(op,custom_severity_level::NOLOG); + break; + + default: + break; + } +} + +void set_global_log_level_operation(log_op::operation op, custom_severity_level threshold ) +{ + switch (op) + { + case log_op::operation::EQUAL : + boost::log::core::get()->set_filter(severity == threshold); + break; + + case log_op::operation::GREATER_THAN : + boost::log::core::get()->set_filter(severity > threshold); + break; + + case log_op::operation::GREATER_EQ_THAN : + boost::log::core::get()->set_filter(severity >= threshold); + break; + + case log_op::operation::LESS_THAN : + boost::log::core::get()->set_filter(severity < threshold); + break; + + case log_op::operation::LESS_EQ_THAN : + boost::log::core::get()->set_filter(severity <= threshold); + break; + + default: + break; + } +} + +void init_new_file(const std::string& filename, custom_severity_level threshold, log_op::operation op) +{ + // add a file text sink with filters but without any formatting + std::string formatted_filename(filename); + formatted_filename+=".%N.txt"; + boost::shared_ptr< sinks::text_file_backend > backend = + boost::make_shared< sinks::text_file_backend > + ( + boost::log::keywords::file_name = formatted_filename, + boost::log::keywords::rotation_size = 10 * 1024 * 1024, + // rotate at midnight every day + boost::log::keywords::time_based_rotation = sinks::file::rotation_at_time_point(0, 0, 0), + // log collector, + // -- maximum total size of the stored log files is 1GB. + // -- minimum free space on the drive is 2GB + boost::log::keywords::max_size = 1000 * 1024 * 1024, + boost::log::keywords::min_free_space = 2000 * 1024 * 1024, + boost::log::keywords::auto_flush = true + //keywords::time_based_rotation = &is_it_time_to_rotate + ); + typedef sinks::synchronous_sink< sinks::text_file_backend > sink_t; + boost::shared_ptr< sink_t > sink(new sink_t(backend)); + + //sink->set_formatter(&init_file_formatter); + + switch (op) + { + case log_op::operation::EQUAL : + sink->set_filter(severity == threshold); + break; + + case log_op::operation::GREATER_THAN : + sink->set_filter(severity > threshold); + break; + + case log_op::operation::GREATER_EQ_THAN : + sink->set_filter(severity >= threshold); + break; + + case log_op::operation::LESS_THAN : + sink->set_filter(severity < threshold); + break; + + case log_op::operation::LESS_EQ_THAN : + sink->set_filter(severity <= threshold); + break; + + default: + break; + } + logging::core::get()->add_sink(sink); +} + diff --git a/fairmq/logger/logger.h b/fairmq/logger/logger.h new file mode 100644 index 00000000..0f3f311d --- /dev/null +++ b/fairmq/logger/logger.h @@ -0,0 +1,129 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence version 3 (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +/* + * File: logger.h + * Author: winckler + * + * Created on August 21, 2015, 6:12 PM + */ +#ifndef LOGGER_H +#define LOGGER_H + +#define BOOST_LOG_DYN_LINK 1 // necessary when linking the boost_log library dynamically + +// std +#include +#include +#include + +// boost +#include +#include +#include +#include +#include +#include +#include +#include + +// fairmq +#include "logger_def.h" + +// Note : the following types and values must be defined in the included logger_def.h : +// 1- custom_severity_level +// 2- SEVERITY_THRESHOLD +// 3- tag_console +// 4- tag_file + +// Note : operation enum temporary : (until we replace it with c++11 lambda expression) +namespace log_op +{ + enum operation + { + EQUAL, + GREATER_THAN, + GREATER_EQ_THAN, + LESS_THAN, + LESS_EQ_THAN + }; +} + + +// declaration of the init function for the global logger +void init_log_console(); +void init_log_file( const std::string& filename, + custom_severity_level threshold=SEVERITY_THRESHOLD, + log_op::operation=log_op::GREATER_EQ_THAN, + const std::string& id="" + ); + +void init_new_file( const std::string& filename, + custom_severity_level threshold, + log_op::operation op + ); + +void set_global_log_level( log_op::operation op=log_op::GREATER_EQ_THAN, + custom_severity_level threshold=SEVERITY_THRESHOLD ); +void set_global_log_level_operation( log_op::operation op=log_op::GREATER_EQ_THAN, + custom_severity_level threshold=SEVERITY_THRESHOLD ); +// register a global logger (declaration) +BOOST_LOG_GLOBAL_LOGGER(global_logger, boost::log::sources::severity_logger_mt) + +BOOST_LOG_ATTRIBUTE_KEYWORD(fairmq_logger_timestamp, "TimeStamp", boost::posix_time::ptime) +BOOST_LOG_ATTRIBUTE_KEYWORD(severity, "Severity", custom_severity_level) + + +template +void init_log_formatter(const boost::log::record_view &view, boost::log::formatting_ostream &os) +{ + os << "[" ; + + if(std::is_same::value) + os<<"\033[01;36m"; + + auto date_time_formatter = + boost::log::expressions::stream + << boost::log::expressions::format_date_time< boost::posix_time::ptime >("TimeStamp", "%H:%M:%S"); + date_time_formatter(view, os); + + if(std::is_same::value) + os<<"\033[0m"; + + os << "]" + << "[" + << view.attribute_values()["Severity"].extract() + << "] " + //<< " - " + << view.attribute_values()["Message"].extract(); +} + + + +// helper macros + +// global macros (core). Level filters are set globally here, that is to all register sinks +#define LOG(severity) BOOST_LOG_SEV(global_logger::get(),custom_severity_level::severity) +#define MQLOG(severity) BOOST_LOG_SEV(global_logger::get(),custom_severity_level::severity) +#define SET_LOG_LEVEL(loglevel) boost::log::core::get()->set_filter(severity >= custom_severity_level::loglevel); +#define SET_LOG_FILTER(op,loglevel) set_global_log_level(log_op::op,custom_severity_level::loglevel) + +// local init macros (sinks) +// Notes : when applying a filter to the sink, and then to the core, the resulting filter will +// be the intersection of the two sets defined by the two filters, i.e., core and sinks +// filename : path to file name without extension +#define INIT_LOG_FILE(filename) init_log_file(filename); +#define INIT_LOG_FILE_LVL(filename,loglevel) init_log_file(filename,custom_severity_level::loglevel); +#define INIT_LOG_FILE_FILTER(filename,op,loglevel) init_log_file(filename,custom_severity_level::loglevel,log_op::op); +//INIT_LOG_FILE_FILTER_MP : add id to log filename for multiprocess +#define INIT_LOG_FILE_FILTER_MP(filename,op,loglevel,id) init_log_file(filename,custom_severity_level::loglevel,log_op::GREATER_EQ_THAN,id); + +// create new file without formatting +#define INIT_NEW_FILE(filename,op,loglevel) init_new_file(filename,custom_severity_level::loglevel,log_op::op); + + +#endif diff --git a/fairmq/logger/logger_def.h b/fairmq/logger/logger_def.h new file mode 100644 index 00000000..16b201c0 --- /dev/null +++ b/fairmq/logger/logger_def.h @@ -0,0 +1,183 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence version 3 (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +/* + * File: logger_def.h + * Author: winckler + * + * Created on September 2, 2015, 11:58 AM + */ + +#ifndef LOGGER_DEF_H +#define LOGGER_DEF_H + +#include +#include +#include + +#include +#include + +namespace fairmq +{ + enum severity_level + { + TRACE, + DEBUG, + RESULTS, + INFO, + WARN, + ERROR, + STATE, + NOLOG + }; + + + static const std::array g_LogSeverityLevelString + { + { + "TRACE", + "DEBUG", + "RESULTS", + "INFO", + "WARN", + "ERROR", + "STATE", + "NOLOG" + } + }; + + + + namespace color + { + enum code + { + FG_BLACK = 30, + FG_RED = 31, + FG_GREEN = 32, + FG_YELLOW = 33, + FG_BLUE = 34, + FG_MAGENTA = 35, + FG_CYAN = 36, + FG_WHITE = 37, + FG_DEFAULT = 39, + BG_RED = 41, + BG_GREEN = 42, + BG_BLUE = 44, + BG_DEFAULT = 49 + }; + } +} + +// helper function to format in color console output +template +inline std::string write_in(const std::string& text_in_bold) +{ + std::ostringstream os; + os << "\033[01;" << color << "m" << text_in_bold << "\033[0m"; + + return os.str(); +} + +// typedef +typedef fairmq::severity_level custom_severity_level; +#define SEVERITY_THRESHOLD custom_severity_level::TRACE + +// tags used for log console or file formatting +struct tag_console; +struct tag_file; + + +// overload operator for console output +inline boost::log::formatting_ostream& operator<< + ( + boost::log::formatting_ostream& strm, + boost::log::to_log_manip< custom_severity_level, tag_console > const& manip + ) +{ + custom_severity_level level = manip.get(); + std::size_t idx=static_cast< std::size_t >(level); + if ( idx < fairmq::g_LogSeverityLevelString.size() ) + { + //strm <<" idx = "<(fairmq::g_LogSeverityLevelString.at(idx)); + break; + + case custom_severity_level::DEBUG : + strm << write_in(fairmq::g_LogSeverityLevelString.at(idx)); + break; + + case custom_severity_level::RESULTS : + strm << write_in(fairmq::g_LogSeverityLevelString.at(idx)); + break; + + case custom_severity_level::INFO : + strm << write_in(fairmq::g_LogSeverityLevelString.at(idx)); + break; + + case custom_severity_level::WARN : + strm << write_in(fairmq::g_LogSeverityLevelString.at(idx)); + break; + + case custom_severity_level::STATE : + strm << write_in(fairmq::g_LogSeverityLevelString.at(idx)); + break; + + case custom_severity_level::ERROR : + strm << write_in(fairmq::g_LogSeverityLevelString.at(idx)); + break; + + case custom_severity_level::NOLOG : + strm << write_in(fairmq::g_LogSeverityLevelString.at(idx)); + break; + + default: + break; + } + + } + else + { + strm << write_in("Unknown log level ") + << "(int level = "<(level) + <<")"; + } + return strm; +} + +// overload operator for file output +inline boost::log::formatting_ostream& operator<< + ( + boost::log::formatting_ostream& strm, + boost::log::to_log_manip< custom_severity_level, tag_file > const& manip + ) +{ + custom_severity_level level = manip.get(); + std::size_t idx=static_cast< std::size_t >(level); + if ( idx < fairmq::g_LogSeverityLevelString.size() ) + strm << fairmq::g_LogSeverityLevelString.at(idx); + else + { + strm << write_in("Unknown log level ") + << "(int level = "<(level) + <<")"; + } + return strm; +} + + + + + + + +#endif /* LOGGER_DEF_H */ + diff --git a/fairmq/logger/run/testLogger.cxx b/fairmq/logger/run/testLogger.cxx new file mode 100644 index 00000000..94016b5f --- /dev/null +++ b/fairmq/logger/run/testLogger.cxx @@ -0,0 +1,66 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence version 3 (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ + +#include "logger.h" + + void test_logger() + { + LOG(TRACE) << "this is a trace message"; + LOG(DEBUG) << "this is a debug message"; + LOG(RESULTS) << "this is a results message"; + LOG(INFO) << "this is a info message"; + LOG(WARN) << "this is a warning message"; + LOG(ERROR) << "this is an error message"; + LOG(STATE) << "this is a state message"; + } + + void test_set_level() + { + std::cout<<"********* test logger : SET_LOG_LEVEL(lvl) *********"<(".id"); - MQLOG(DEBUG) << "Found device id '" << deviceIdKey << "' in XML input"; + LOG(DEBUG) << "Found device id '" << deviceIdKey << "' in XML input"; } if (formatFlag == "json") { deviceIdKey = p.second.get("id"); - MQLOG(DEBUG) << "Found device id '"<< deviceIdKey << "' in JSON input"; + LOG(DEBUG) << "Found device id '"<< deviceIdKey << "' in JSON input"; } } @@ -88,7 +88,7 @@ FairMQMap ptreeToMQMap(const boost::property_tree::ptree& pt, const std::string& std::stringstream deviceStream; deviceStream << "[node = " << p.first << "] id = " << deviceIdKey; - MQLOG(DEBUG) << deviceStream.str(); + LOG(DEBUG) << deviceStream.str(); // for each channel in device for(const auto& q : p.second.get_child("")) @@ -113,7 +113,7 @@ FairMQMap ptreeToMQMap(const boost::property_tree::ptree& pt, const std::string& std::stringstream channelStream; channelStream << "\t [node = " << q.first << "] name = " << channelKey; - MQLOG(DEBUG) << channelStream.str(); + LOG(DEBUG) << channelStream.str(); // temporary FairMQChannel container std::vector channelList; @@ -134,13 +134,13 @@ FairMQMap ptreeToMQMap(const boost::property_tree::ptree& pt, const std::string& std::stringstream socket; socket << "\t \t [node = " << r.first << "] socket index = " << socketCounter; - MQLOG(DEBUG) << socket.str(); - MQLOG(DEBUG) << "\t \t \t type = " << r.second.get("type", channel.GetType()); - MQLOG(DEBUG) << "\t \t \t method = " << r.second.get("method", channel.GetMethod()); - MQLOG(DEBUG) << "\t \t \t address = " << r.second.get("address", channel.GetAddress()); - MQLOG(DEBUG) << "\t \t \t sndBufSize = " << r.second.get("sndBufSize", channel.GetSndBufSize()); - MQLOG(DEBUG) << "\t \t \t rcvBufSize = " << r.second.get("rcvBufSize", channel.GetRcvBufSize()); - MQLOG(DEBUG) << "\t \t \t rateLogging = " << r.second.get("rateLogging", channel.GetRateLogging()); + LOG(DEBUG) << socket.str(); + LOG(DEBUG) << "\t \t \t type = " << r.second.get("type", channel.GetType()); + LOG(DEBUG) << "\t \t \t method = " << r.second.get("method", channel.GetMethod()); + LOG(DEBUG) << "\t \t \t address = " << r.second.get("address", channel.GetAddress()); + LOG(DEBUG) << "\t \t \t sndBufSize = " << r.second.get("sndBufSize", channel.GetSndBufSize()); + LOG(DEBUG) << "\t \t \t rcvBufSize = " << r.second.get("rcvBufSize", channel.GetRcvBufSize()); + LOG(DEBUG) << "\t \t \t rateLogging = " << r.second.get("rateLogging", channel.GetRateLogging()); channel.UpdateType(r.second.get("type", channel.GetType())); channel.UpdateMethod(r.second.get("method", channel.GetMethod())); @@ -159,16 +159,16 @@ FairMQMap ptreeToMQMap(const boost::property_tree::ptree& pt, const std::string& if (MQChannelMap.size() > 0) { - MQLOG(DEBUG) << "---- Channel-keys found are :"; + LOG(DEBUG) << "---- Channel-keys found are :"; for (const auto& p : MQChannelMap) { - MQLOG(DEBUG) << p.first; + LOG(DEBUG) << p.first; } } else { - MQLOG(WARN) << "---- No channel-keys found for device-id " << deviceId; - MQLOG(WARN) << "---- Check the "<< formatFlag << " inputs and/or command line inputs"; + LOG(WARN) << "---- No channel-keys found for device-id " << deviceId; + LOG(WARN) << "---- Check the "<< formatFlag << " inputs and/or command line inputs"; } return MQChannelMap; } diff --git a/fairmq/options/FairMQProgOptions.cxx b/fairmq/options/FairMQProgOptions.cxx index e38d325d..2deba455 100644 --- a/fairmq/options/FairMQProgOptions.cxx +++ b/fairmq/options/FairMQProgOptions.cxx @@ -57,8 +57,17 @@ int FairMQProgOptions::ParseAll(const int argc, char** argv, bool AllowUnregiste } // set log level before printing (default is 0 = DEBUG level) - int verbose=GetValue("verbose"); - SET_LOGGER_LEVEL(verbose); + std::string verbose=GetValue("verbose"); + //SET_LOG_LEVEL(DEBUG); + if(fSeverity_map.count(verbose)) + { + set_global_log_level(log_op::operation::GREATER_EQ_THAN,fSeverity_map.at(verbose)); + } + else + { + LOG(ERROR)<<" verbosity level '"<(&fVerboseLvl)->default_value(0), "Verbosity level : \n" - " 0=DEBUG \n" - " 1=INFO \n" - " 2=WARN \n" - " 3=ERROR \n" - " 4=STATE \n" - " 5=NOLOG" + ("verbose", po::value(&fVerboseLvl)->default_value("INFO"), "Verbosity level : \n" + " TRACE \n" + " DEBUG \n" + " RESULTS \n" + " INFO \n" + " WARN \n" + " ERROR \n" + " STATE \n" + " NOLOG" ) ; + fSeverity_map["TRACE"] = fairmq::severity_level::TRACE; + fSeverity_map["DEBUG"] = fairmq::severity_level::DEBUG; + fSeverity_map["RESULTS"] = fairmq::severity_level::RESULTS; + fSeverity_map["INFO"] = fairmq::severity_level::INFO; + fSeverity_map["WARN"] = fairmq::severity_level::WARN; + fSeverity_map["ERROR"] = fairmq::severity_level::ERROR; + fSeverity_map["STATE"] = fairmq::severity_level::STATE; + fSeverity_map["NOLOG"] = fairmq::severity_level::NOLOG; + } FairProgOptions::~FairProgOptions() @@ -255,8 +266,8 @@ std::string FairProgOptions::GetStringValue(const std::string& key) } catch(std::exception& e) { - MQLOG(ERROR) << "Exception thrown for the key '" << key << "'"; - MQLOG(ERROR) << e.what(); + LOG(ERROR) << "Exception thrown for the key '" << key << "'"; + LOG(ERROR) << e.what(); } return val_str; @@ -320,7 +331,7 @@ int FairProgOptions::PrintOptions() // formatting and printing - MQLOG(INFO)<