9 #include "messagefacility/MessageLogger/MessageLogger.h"
11 #include "fhiclcpp/make_ParameterSet.h"
12 #include "fhiclcpp/ParameterSet.h"
14 #include <boost/program_options.hpp>
15 #include <boost/filesystem.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");
46 (
"help,h",
"display help message")
48 po::value<std::string>(&severity)->default_value(
"info"),
49 "severity of the message (error, warning, info, debug)")
51 po::value<std::vector<std::string>>(&vcat)->default_value(vcat_def,
"null"),
52 "message id / categories")
54 po::value<std::string>(&application)->default_value(
"msgsenderApplication"),
55 "issuing application name")
57 po::value<std::string>(&conf)->default_value(
""),
58 "MessageFacility configuration file")
59 (
"dump,d", po::bool_switch(&dump)->default_value(
false));
61 po::options_description hidden(
"Hidden options");
63 (
"message", po::value<std::vector<std::string>>(&messages),
"message text");
65 po::options_description desc;
66 desc.add(cmdopt).add(hidden);
68 po::positional_options_description p;
72 po::store(po::command_line_parser(ac, av).options(desc).positional(p).run(), vm);
77 std::cout <<
"Usage: msglogger [options] <message text>\n";
82 catch (std::exception& e)
84 std::cerr <<
"error: " << e.what() <<
"\n";
89 std::cerr <<
"Exception of unknown type!\n";
93 std::vector<std::string>::iterator it;
96 if (messages.size() == 0)
98 std::cout <<
"Message text is missing!\n";
99 std::cout <<
"Use \"msglogger --help\" for help messages\n";
103 if (application.empty())
105 std::cout <<
"Application name is missing!\n";
106 std::cout <<
"Message cannot be issued without specifying the application name.\n";
111 it = messages.begin();
112 while (it != messages.end())
114 message += *it +
" ";
119 transform(severity.begin(), severity.end(), severity.begin(), ::toupper);
120 if ((severity !=
"ERROR") && (severity !=
"WARNING")
121 && (severity !=
"INFO") && (severity !=
"DEBUG"))
123 std::cerr <<
"Unknown severity level!\n";
129 while (it != vcat.end())
131 cat += *it + ((it == vcat.end() - 1) ?
"" :
"|");
136 fhicl::ParameterSet pset;
138 std::ifstream logfhicl(conf);
139 if (logfhicl.is_open())
141 std::stringstream fhiclstream;
142 fhiclstream << logfhicl.rdbuf();
143 std::string pstr(fhiclstream.str());
144 fhicl::make_ParameterSet(pstr, pset);
146 # if MESSAGEFACILITY_HEX_VERSION < 0x20002 // an indication of a switch from s48 to s50
149 pset = mf::MessageFacilityService::logConsole();
154 # if MESSAGEFACILITY_HEX_VERSION >= 0x20002 // an indication of a switch from s48 to s50
155 mf::StartMessageFacility(pset);
157 mf::StartMessageFacility(mf::MessageFacilityService::MultiThread, pset);
161 std::cout << pset.to_indented_string() << std::endl;
163 # if MESSAGEFACILITY_HEX_VERSION < 0x20002 // an indication of a switch from s48 to s50
164 mf::SetModuleName(
"msgsenderModule");
165 mf::SetContext(
"msgsenderContext");
167 mf::SetApplicationName(application);
170 if (severity ==
"ERROR")
171 mf::LogError(cat) << message;
172 else if (severity ==
"WARNING")
173 mf::LogWarning(cat) << message;
174 else if (severity ==
"INFO")
175 mf::LogInfo(cat) << message;
176 else if (severity ==
"DEBUG")
177 mf::LogDebug(cat) << message;