1 #include "otsdaq-core/MessageFacility/configureMessageFacility.hh"
2 #include "otsdaq-core/Macros/CoutHeaderMacros.h"
3 #include "messagefacility/MessageLogger/MessageLogger.h"
4 #include "fhiclcpp/make_ParameterSet.h"
5 #include <boost/filesystem.hpp>
11 namespace BFS = boost::filesystem;
13 void ots::configureMessageFacility(
char const* progname)
15 if(!messagefacility_initialized)
17 std::cout << __COUT_HDR_FL__ <<
"#######################################################################" << std::endl;
18 std::cout << __COUT_HDR_FL__ <<
"Initializing MessageFacility with progname " << progname << std::endl;
19 std::cout << __COUT_HDR_FL__ <<
"#######################################################################" << std::endl;
20 std::string logPathProblem =
"";
21 std::string logfileName =
"";
22 char* logRootString = getenv(
"OTSDAQ_LOG_ROOT");
23 char* logFhiclCode = getenv(
"OTSDAQ_LOG_FHICL");
25 if (logRootString !=
nullptr)
27 if (! BFS::exists(logRootString))
29 logPathProblem =
"Log file root directory ";
30 logPathProblem.append(logRootString);
31 logPathProblem.append(
" does not exist!");
33 logfileName = std::string(logRootString);
37 std::ostringstream ss;
38 ss <<
"debugModules:[\"*\"] statistics:[\"stats\"] "
39 <<
" destinations : { "
56 if (logFhiclCode !=
nullptr)
58 std::ifstream logfhicl( logFhiclCode );
60 if ( logfhicl.is_open() )
62 std::stringstream fhiclstream;
63 fhiclstream << logfhicl.rdbuf();
64 ss << fhiclstream.str();
68 std::cout << __COUT_HDR_FL__ <<
69 "Unable to open requested fhicl file \"" <<
70 logFhiclCode <<
"\".";
77 std::cout << __COUT_HDR_FL__ <<
"Configuring MessageFacility with Parameter Set: " << ss.str() << std::endl;
78 fhicl::ParameterSet pset;
79 std::string pstr(ss.str());
80 fhicl::make_ParameterSet(pstr, pset);
82 mf::StartMessageFacility(mf::MessageFacilityService::MultiThread,
85 if (logPathProblem.size() > 0)
87 mf::LogError(progname) << logPathProblem;
89 messagefacility_initialized =
true;
93 void ots::setMsgFacAppName(
const std::string& appType)
95 std::string appName(appType);
98 if (gethostname(&hostname[0], 256) == 0) {
99 std::string hostString(hostname);
100 size_t pos = hostString.find(
".");
101 if (pos != std::string::npos && pos > 2) {
102 hostString = hostString.substr(0, pos);
105 appName.append(hostString);
107 mf::SetApplicationName(appName);
108 mf::SetModuleName(appName);
109 mf::SetContext(appName);