9 #include "messagefacility/MessageLogger/MessageLogger.h"
11 #include "fhiclcpp/ParameterSet.h"
12 #include "fhiclcpp/make_ParameterSet.h"
14 #include <boost/filesystem.hpp>
15 #include <boost/program_options.hpp>
17 using namespace boost;
18 namespace BFS = boost::filesystem;
19 namespace po = boost::program_options;
26 int main(
int ac,
char* av[])
29 std::string application;
35 std::vector<std::string> messages;
36 std::vector<std::string> vcat;
38 std::vector<std::string> vcat_def;
40 vcat_def.push_back(
"");
44 po::options_description cmdopt(
"Allowed options");
45 cmdopt.add_options()(
"help,h",
"display help message")(
"severity,s",
46 po::value<std::string>(&severity)->default_value(
"info"),
47 "severity of the message (error, warning, info, debug)")(
48 "category,g", po::value<std::vector<std::string>>(&vcat)->default_value(vcat_def,
"null"),
49 "message id / categories")(
"application,a",
50 po::value<std::string>(&application)->default_value(
"msgsenderApplication"),
51 "issuing application name")(
52 "config,c", po::value<std::string>(&conf)->default_value(
""),
"MessageFacility configuration file")(
53 "dump,d", po::bool_switch(&dump)->default_value(
false));
55 po::options_description hidden(
"Hidden options");
56 hidden.add_options()(
"message", po::value<std::vector<std::string>>(&messages),
"message text");
58 po::options_description desc;
59 desc.add(cmdopt).add(hidden);
61 po::positional_options_description p;
65 po::store(po::command_line_parser(ac, av).options(desc).positional(p).run(), vm);
70 std::cout <<
"Usage: msglogger [options] <message text>\n";
75 catch (std::exception& e)
77 std::cerr <<
"error: " << e.what() <<
"\n";
82 std::cerr <<
"Exception of unknown type!\n";
86 std::vector<std::string>::iterator it;
89 if (messages.size() == 0)
91 std::cout <<
"Message text is missing!\n";
92 std::cout <<
"Use \"msglogger --help\" for help messages\n";
96 if (application.empty())
98 std::cout <<
"Application name is missing!\n";
99 std::cout <<
"Message cannot be issued without specifying the application name.\n";
104 it = messages.begin();
105 while (it != messages.end())
107 message += *it +
" ";
112 transform(severity.begin(), severity.end(), severity.begin(), ::toupper);
113 if ((severity !=
"ERROR") && (severity !=
"WARNING") && (severity !=
"INFO") && (severity !=
"DEBUG"))
115 std::cerr <<
"Unknown severity level!\n";
121 while (it != vcat.end())
123 cat += *it + ((it == vcat.end() - 1) ?
"" :
"|");
128 fhicl::ParameterSet pset;
130 std::ifstream logfhicl(conf);
131 if (logfhicl.is_open())
133 std::stringstream fhiclstream;
134 fhiclstream << logfhicl.rdbuf();
135 std::string pstr(fhiclstream.str());
136 fhicl::make_ParameterSet(pstr, pset);
140 mf::StartMessageFacility(pset);
143 std::cout << pset.to_indented_string() << std::endl;
145 mf::SetApplicationName(application);
148 if (severity ==
"ERROR")
149 mf::LogError(cat) << message;
150 else if (severity ==
"WARNING")
151 mf::LogWarning(cat) << message;
152 else if (severity ==
"INFO")
153 mf::LogInfo(cat) << message;
154 else if (severity ==
"DEBUG")
155 mf::LogDebug(cat) << message;