mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-15 09:31:45 +00:00
Single Logger implementation for FairLogger & FairMQLogger
This commit is contained in:
committed by
Mohammad Al-Turany
parent
d3e0b9fc97
commit
4e942e489b
@@ -10,19 +10,13 @@
|
||||
#include "FairMQParser.h"
|
||||
#include "FairMQProgOptions.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
// tests
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
// Parse xml from file
|
||||
int testXML1(FairMQProgOptions* config)
|
||||
{
|
||||
LOG(INFO)<<"--------- test XML1 ---------\n";
|
||||
std::string filename;
|
||||
std::string XMLrootNode;
|
||||
|
||||
|
||||
filename=config->GetValue<std::string>("config-xml-file");
|
||||
XMLrootNode=config->GetValue<std::string>("xml.config.node.root");
|
||||
std::string id=config->GetValue<std::string>("id");
|
||||
@@ -30,12 +24,11 @@ int testXML1(FairMQProgOptions* config)
|
||||
// other xml parser test
|
||||
config->UserParser<FairMQParser::MQXML2>(filename);
|
||||
config->UserParser<FairMQParser::MQXML3>(filename,"merger");
|
||||
|
||||
|
||||
LOG(INFO)<<"--------- test XML1 end ---------\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// Parse xml from command line
|
||||
int testXML2(FairMQProgOptions* config)
|
||||
{
|
||||
@@ -44,14 +37,14 @@ int testXML2(FairMQProgOptions* config)
|
||||
std::string XMLrootNode;
|
||||
std::string id=config->GetValue<std::string>("id");
|
||||
XMLrootNode=config->GetValue<std::string>("xml.config.node.root");
|
||||
|
||||
|
||||
// Note: convert the vector<string> into one string with GetStringValue(key)
|
||||
XML=config->GetStringValue("config-xml-string");
|
||||
|
||||
|
||||
std::stringstream iss;
|
||||
iss << XML;
|
||||
config->UserParser<FairMQParser::XML>(iss,id,XMLrootNode);
|
||||
|
||||
|
||||
LOG(INFO)<<"--------- test XML2 end ---------\n";
|
||||
return 0;
|
||||
}
|
||||
@@ -63,12 +56,12 @@ int testJSON1(FairMQProgOptions* config)
|
||||
std::string filename;
|
||||
std::string JSONrootNode;
|
||||
std::string id=config->GetValue<std::string>("id");
|
||||
|
||||
|
||||
filename=config->GetValue<std::string>("config-json-file");
|
||||
JSONrootNode=config->GetValue<std::string>("json.config.node.root");
|
||||
|
||||
|
||||
config->UserParser<FairMQParser::JSON>(filename,id,JSONrootNode);
|
||||
|
||||
|
||||
LOG(INFO)<<"--------- test JSON1 end ---------\n";
|
||||
return 0;
|
||||
}
|
||||
@@ -81,59 +74,63 @@ int testJSON2(FairMQProgOptions* config)
|
||||
std::string JSONrootNode;
|
||||
std::string id=config->GetValue<std::string>("id");
|
||||
JSONrootNode=config->GetValue<std::string>("json.config.node.root");
|
||||
|
||||
|
||||
// Note: convert the vector<string> into one string with GetStringValue(key)
|
||||
JSON=config->GetStringValue("config-json-string");
|
||||
|
||||
|
||||
std::stringstream iss;
|
||||
iss << JSON;
|
||||
config->UserParser<FairMQParser::JSON>(iss,id,JSONrootNode);
|
||||
|
||||
|
||||
LOG(INFO)<<"--------- test JSON2 end ---------\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
/// main
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
FairMQProgOptions* config= new FairMQProgOptions();
|
||||
try
|
||||
{
|
||||
po::options_description format_desc("XML or JSON input");
|
||||
format_desc.add_options()
|
||||
format_desc.add_options()
|
||||
("xml.config.node.root", po::value<std::string>()->default_value("fairMQOptions"), "xml root node ")
|
||||
("json.config.node.root", po::value<std::string>()->default_value("fairMQOptions"), "json root node ")
|
||||
;
|
||||
|
||||
|
||||
config->AddToCmdLineOptions(format_desc);
|
||||
|
||||
// Parse command line
|
||||
if(config->ParseAll(argc,argv))
|
||||
if (config->ParseAll(argc,argv))
|
||||
{
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
// Set severity level (Default is 0=DEBUG)
|
||||
int verbosity = config->GetValue<int>("verbosity");
|
||||
FairMQLogger::Level lvl=static_cast<FairMQLogger::Level>(verbosity);
|
||||
int severity = config->GetValue<int>("severity");
|
||||
FairMQLogger::Level lvl=static_cast<FairMQLogger::Level>(severity);
|
||||
SET_LOGGER_LEVEL(lvl);
|
||||
|
||||
|
||||
|
||||
// Parse xml or json from cmd line or file
|
||||
|
||||
if(config->GetVarMap().count("config-xml-file"))
|
||||
if (config->GetVarMap().count("config-xml-file"))
|
||||
{
|
||||
testXML1(config);
|
||||
|
||||
if(config->GetVarMap().count("config-xml-string"))
|
||||
}
|
||||
|
||||
if (config->GetVarMap().count("config-xml-string"))
|
||||
{
|
||||
testXML2(config);
|
||||
|
||||
if(config->GetVarMap().count("config-json-file"))
|
||||
}
|
||||
|
||||
if (config->GetVarMap().count("config-json-file"))
|
||||
{
|
||||
testJSON1(config);
|
||||
|
||||
if(config->GetVarMap().count("config-json-string"))
|
||||
}
|
||||
|
||||
if (config->GetVarMap().count("config-json-string"))
|
||||
{
|
||||
testJSON2(config);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
@@ -142,9 +139,3 @@ int main(int argc, char** argv)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -15,17 +15,16 @@
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
||||
{
|
||||
try
|
||||
{
|
||||
FairMQProgOptions config;
|
||||
|
||||
|
||||
po::options_description format_desc("XML input");
|
||||
format_desc.add_options()
|
||||
("xml.config.node.root", po::value<std::string>()->default_value("fairMQOptions"), "xml root node ")
|
||||
;
|
||||
|
||||
|
||||
po::options_description io_file_opt_desc("I/O file Options");
|
||||
io_file_opt_desc.add_options()
|
||||
("input.file.name", po::value<std::string>(), "input file name")
|
||||
@@ -38,21 +37,20 @@ int main(int argc, char** argv)
|
||||
|
||||
config.AddToCmdLineOptions(format_desc,true);
|
||||
config.AddToCmdLineOptions(io_file_opt_desc,true);
|
||||
|
||||
|
||||
|
||||
config.EnableCfgFile();// UseConfigFile (by default config file is not defined)
|
||||
config.AddToCfgFileOptions(format_desc,false);//false because already added to visible
|
||||
config.AddToCfgFileOptions(io_file_opt_desc,false);
|
||||
|
||||
|
||||
// Parse command line and config file
|
||||
if(config.ParseAll(argc,argv))
|
||||
return 0;
|
||||
|
||||
|
||||
// Set severity level (Default is 0=DEBUG)
|
||||
int verbosity=config.GetValue<int>("verbosity");
|
||||
FairMQLogger::Level lvl=static_cast<FairMQLogger::Level>(verbosity);
|
||||
int severity = config.GetValue<int>("severity");
|
||||
FairMQLogger::Level lvl = static_cast<FairMQLogger::Level>(severity);
|
||||
SET_LOGGER_LEVEL(lvl);
|
||||
|
||||
|
||||
// parse XML file
|
||||
std::string filename;
|
||||
std::string XMLrootNode;
|
||||
@@ -61,8 +59,6 @@ int main(int argc, char** argv)
|
||||
XMLrootNode=config.GetValue<std::string>("xml.config.node.root");
|
||||
std::string id=config.GetValue<std::string>("id");
|
||||
config.UserParser<FairMQParser::XML>(filename,id,XMLrootNode);
|
||||
|
||||
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
@@ -71,9 +67,3 @@ int main(int argc, char** argv)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user