mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-16 01:51:45 +00:00
- Replace the fairmq logger with one based on Boost.Log
- Adapt FairProgOptions to the new logger
This commit is contained in:
committed by
Mohammad Al-Turany
parent
bea05ea6c1
commit
e0ca1f62b3
@@ -48,13 +48,13 @@ FairMQMap ptreeToMQMap(const boost::property_tree::ptree& pt, const std::string&
|
||||
if (formatFlag == "xml")
|
||||
{
|
||||
deviceIdKey = p.second.get<std::string>("<xmlattr>.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<std::string>("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<FairMQChannel> 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<std::string>("type", channel.GetType());
|
||||
MQLOG(DEBUG) << "\t \t \t method = " << r.second.get<std::string>("method", channel.GetMethod());
|
||||
MQLOG(DEBUG) << "\t \t \t address = " << r.second.get<std::string>("address", channel.GetAddress());
|
||||
MQLOG(DEBUG) << "\t \t \t sndBufSize = " << r.second.get<int>("sndBufSize", channel.GetSndBufSize());
|
||||
MQLOG(DEBUG) << "\t \t \t rcvBufSize = " << r.second.get<int>("rcvBufSize", channel.GetRcvBufSize());
|
||||
MQLOG(DEBUG) << "\t \t \t rateLogging = " << r.second.get<int>("rateLogging", channel.GetRateLogging());
|
||||
LOG(DEBUG) << socket.str();
|
||||
LOG(DEBUG) << "\t \t \t type = " << r.second.get<std::string>("type", channel.GetType());
|
||||
LOG(DEBUG) << "\t \t \t method = " << r.second.get<std::string>("method", channel.GetMethod());
|
||||
LOG(DEBUG) << "\t \t \t address = " << r.second.get<std::string>("address", channel.GetAddress());
|
||||
LOG(DEBUG) << "\t \t \t sndBufSize = " << r.second.get<int>("sndBufSize", channel.GetSndBufSize());
|
||||
LOG(DEBUG) << "\t \t \t rcvBufSize = " << r.second.get<int>("rcvBufSize", channel.GetRcvBufSize());
|
||||
LOG(DEBUG) << "\t \t \t rateLogging = " << r.second.get<int>("rateLogging", channel.GetRateLogging());
|
||||
|
||||
channel.UpdateType(r.second.get<std::string>("type", channel.GetType()));
|
||||
channel.UpdateMethod(r.second.get<std::string>("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;
|
||||
}
|
||||
|
@@ -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<int>("verbose");
|
||||
SET_LOGGER_LEVEL(verbose);
|
||||
std::string verbose=GetValue<std::string>("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 '"<<verbose<<"' unknown, it will be set to INFO";
|
||||
set_global_log_level(log_op::operation::GREATER_EQ_THAN,fSeverity_map.at("RESULTS"));
|
||||
}
|
||||
|
||||
PrintOptions();
|
||||
|
||||
|
@@ -45,7 +45,7 @@ public:
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
MQLOG(ERROR) << e.what();
|
||||
LOG(ERROR) << e.what();
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
@@ -27,23 +27,34 @@ FairProgOptions::FairProgOptions() :
|
||||
fCmdline_options("Command line options"),
|
||||
fConfig_file_options("Configuration file options"),
|
||||
fVisible_options("Visible options"),
|
||||
fVerboseLvl(0), fUseConfigFile(false), fConfigFile()
|
||||
fVerboseLvl("INFO"), fUseConfigFile(false), fConfigFile()
|
||||
{
|
||||
// //////////////////////////////////
|
||||
// define generic options
|
||||
fGenericDesc.add_options()
|
||||
("help,h", "produce help")
|
||||
("version,v", "print version")
|
||||
("verbose", po::value<int>(&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<std::string>(&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)<<std::setfill ('*') << std::setw (total_len+3)<<"*";// +3 because of string " = "
|
||||
LOG(INFO)<<std::setfill ('*') << std::setw (total_len+3)<<"*";// +3 because of string " = "
|
||||
std::string PrintOptionsTitle=" Program options found ";
|
||||
|
||||
int leftSpace_len=0;
|
||||
@@ -342,11 +353,12 @@ int FairProgOptions::PrintOptions()
|
||||
rightSpace_len=(total_len+3)/2-rightTitle_shift_len;
|
||||
|
||||
|
||||
MQLOG(INFO) <<std::setfill ('*') << std::setw(leftSpace_len) <<"*"
|
||||
<<std::setw(PrintOptionsTitle.length()) << PrintOptionsTitle
|
||||
<<std::setfill ('*') << std::setw(rightSpace_len) <<"*";
|
||||
LOG(INFO) << std::setfill ('*') << std::setw(leftSpace_len) <<"*"
|
||||
<< std::setfill(' ')
|
||||
<< std::setw(PrintOptionsTitle.length()) << PrintOptionsTitle
|
||||
<< std::setfill ('*') << std::setw(rightSpace_len) <<"*";
|
||||
|
||||
MQLOG(INFO) <<std::setfill ('*') << std::setw (total_len+3)<<"*";
|
||||
LOG(INFO) <<std::setfill ('*') << std::setw (total_len+3)<<"*";
|
||||
|
||||
for (const auto& p : mapinfo)
|
||||
{
|
||||
@@ -357,7 +369,8 @@ int FairProgOptions::PrintOptions()
|
||||
std::string empty_str;
|
||||
key_str=p.first;
|
||||
std::tie(val_str,typeInfo_str,default_str,empty_str)=p.second;
|
||||
MQLOG(INFO) << std::setw(maxlen_1st)<<std::left
|
||||
LOG(INFO) << std::setfill(' ')
|
||||
<< std::setw(maxlen_1st)<<std::left
|
||||
<< p.first << " = "
|
||||
<< std::setw(maxlen_2nd)
|
||||
<< val_str
|
||||
@@ -368,7 +381,7 @@ int FairProgOptions::PrintOptions()
|
||||
<< std::setw(maxlen_empty)
|
||||
<< empty_str;
|
||||
}
|
||||
MQLOG(INFO)<<std::setfill ('*') << std::setw (total_len+3)<<"*";// +3 for " = "
|
||||
LOG(INFO)<<std::setfill ('*') << std::setw (total_len+3)<<"*";// +3 for " = "
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@@ -136,8 +136,11 @@ protected:
|
||||
|
||||
// Description which is printed in help command line
|
||||
po::options_description fVisible_options;
|
||||
|
||||
// to handle logger severity
|
||||
std::map<std::string,fairmq::severity_level> fSeverity_map;
|
||||
|
||||
int fVerboseLvl;
|
||||
std::string fVerboseLvl;
|
||||
bool fUseConfigFile;
|
||||
boost::filesystem::path fConfigFile;
|
||||
virtual int NotifySwitchOption();
|
||||
|
Reference in New Issue
Block a user