9 #include "messagefacility/MessageLogger/MessageLogger.h"
11 #include "fhiclcpp/ParameterSet.h"
13 #include <boost/filesystem.hpp>
14 #include <boost/program_options.hpp>
16 using namespace boost;
17 namespace po = boost::program_options;
24 int main(
int ac,
char* av[])
27 std::string application;
33 std::vector<std::string> messages;
34 std::vector<std::string> vcat;
36 std::vector<std::string> vcat_def;
38 vcat_def.emplace_back(
"");
42 po::options_description cmdopt(
"Allowed options");
43 cmdopt.add_options()(
"help,h",
"display help message")(
"severity,s",
44 po::value<std::string>(&severity)->default_value(
"info"),
45 "severity of the message (error, warning, info, debug)")(
46 "category,g", po::value<std::vector<std::string>>(&vcat)->default_value(vcat_def,
"null"),
47 "message id / categories")(
"application,a",
48 po::value<std::string>(&application)->default_value(
"msgsenderApplication"),
49 "issuing application name")(
50 "config,c", po::value<std::string>(&conf)->default_value(
""),
"MessageFacility configuration file")(
51 "dump,d", po::bool_switch(&dump)->default_value(
false));
53 po::options_description hidden(
"Hidden options");
54 hidden.add_options()(
"message", po::value<std::vector<std::string>>(&messages),
"message text");
56 po::options_description desc;
57 desc.add(cmdopt).add(hidden);
59 po::positional_options_description p;
63 po::store(po::command_line_parser(ac, av).options(desc).positional(p).run(), vm);
66 if (vm.count(
"help") != 0u)
68 std::cout <<
"Usage: msglogger [options] <message text>\n";
73 catch (std::exception& e)
75 std::cerr <<
"error: " << e.what() <<
"\n";
80 std::cerr <<
"Exception of unknown type!\n";
84 std::vector<std::string>::iterator it;
89 std::cout <<
"Message text is missing!\n";
90 std::cout <<
"Use \"msglogger --help\" for help messages\n";
94 if (application.empty())
96 std::cout <<
"Application name is missing!\n";
97 std::cout <<
"Message cannot be issued without specifying the application name.\n";
102 it = messages.begin();
103 while (it != messages.end())
105 message += *it +
" ";
110 transform(severity.begin(), severity.end(), severity.begin(), ::toupper);
111 if ((severity !=
"ERROR") && (severity !=
"WARNING") && (severity !=
"INFO") && (severity !=
"DEBUG"))
113 std::cerr <<
"Unknown severity level!\n";
119 while (it != vcat.end())
121 cat += *it + ((it == vcat.end() - 1) ?
"" :
"|");
126 fhicl::ParameterSet pset;
128 std::ifstream logfhicl(conf);
129 if (logfhicl.is_open())
131 std::stringstream fhiclstream;
132 fhiclstream << logfhicl.rdbuf();
133 std::string pstr(fhiclstream.str());
134 pset = fhicl::ParameterSet::make(pstr);
138 mf::StartMessageFacility(pset);
141 std::cout << pset.to_indented_string() << std::endl;
143 mf::SetApplicationName(application);
146 if (severity ==
"ERROR")
148 mf::LogError(cat) << message;
150 else if (severity ==
"WARNING")
152 mf::LogWarning(cat) << message;
154 else if (severity ==
"INFO")
156 mf::LogInfo(cat) << message;
158 else if (severity ==
"DEBUG")
160 mf::LogDebug(cat) << message;