1 #include "cetlib/PluginTypeDeducer.h"
2 #include "cetlib/ostream_handle.h"
3 #include "fhiclcpp/ParameterSet.h"
5 #include "cetlib/compiler_macros.h"
6 #include "messagefacility/MessageService/ELdestination.h"
7 #include "messagefacility/Utilities/ELseverityLevel.h"
8 #include "messagefacility/Utilities/exception.h"
13 using mf::ELseverityLevel;
15 using mf::service::ELdestination;
29 fhicl::Atom<std::string>
baseDir = fhicl::Atom<std::string>{
30 fhicl::Name{
"base_directory"}, fhicl::Comment{
"Directory where log files will be created"},
"/tmp"};
33 fhicl::Atom<bool>{fhicl::Name{
"append"}, fhicl::Comment{
"Append to existing log files"},
true};
36 fhicl::Name{
"use_hostname"}, fhicl::Comment{
"Use the hostname when generating log file names"},
true};
39 fhicl::Atom<bool>{fhicl::Name{
"use_application"},
40 fhicl::Comment{
"Use the application field when generating log file names"},
true};
43 fhicl::Name{
"use_category"}, fhicl::Comment{
"Use the category field when generating log file names"},
false};
46 fhicl::Name{
"use_module"},
47 fhicl::Comment{
"Use the module field when generating log file names"},
false};
69 virtual void routePayload(
const std::ostringstream& oss,
const ErrorObj& msg)
override;
74 virtual void flush()
override;
79 std::unordered_map<std::string, std::unique_ptr<cet::ostream_handle>> outputs_;
95 : ELdestination(pset().elDestConfig()),
96 baseDir_(pset().baseDir()),
97 append_(pset().append()),
98 useHost_(pset().useHostname()),
99 useApplication_(pset().useApplication()),
100 useCategory_(pset().useCategory()),
101 useModule_(pset().useModule()) {}
107 const auto& xid = msg.xid();
108 std::string fileName = baseDir_ +
"/";
110 fileName += xid.module() +
"-";
113 fileName += xid.id() +
"-";
115 if (useApplication_) {
116 fileName += xid.application() +
"-";
119 fileName += xid.hostname() +
"-";
121 fileName += std::to_string(xid.pid()) +
".log";
122 if (outputs_.count(fileName) == 0) {
124 std::make_unique<cet::ostream_handle>(fileName.c_str(), append_ ? std::ios::app : std::ios::trunc);
126 *outputs_[fileName] << oss.str();
131 for (
auto i = outputs_.begin(); i != outputs_.end(); ++i) {
132 (*i).second->flush();
143 #ifndef EXTERN_C_FUNC_DECLARE_START
144 #define EXTERN_C_FUNC_DECLARE_START extern "C" {
147 EXTERN_C_FUNC_DECLARE_START
148 auto makePlugin(
const std::string&,
const fhicl::ParameterSet& pset) {
149 return std::make_unique<mfplugins::ELMultiFileOutput>(pset);
153 DEFINE_BASIC_PLUGINTYPE_FUNC(mf::service::ELdestination)
fhicl::Atom< bool > append
"append" (Default: true): Append to existing log files
Message Facility Destination which automatically opens files and sorts messages into them based on gi...
fhicl::Atom< std::string > baseDir
"base_directory" (Default: "/tmp"): Directory where log files will be created
fhicl::Atom< bool > useCategory
"use_category" (Default: false): Use the category field when generating log file names ...
ELMultiFileOutput(Parameters const &pset)
ELMultiFileOutput Constructor
fhicl::Atom< bool > useHostname
"use_hostname" (Default: true): Use the hostname when generating log file names
fhicl::WrappedTable< Config > Parameters
Used for ParameterSet validation.
virtual ~ELMultiFileOutput()
Default virtual Destructor
virtual void routePayload(const std::ostringstream &oss, const ErrorObj &msg) override
Serialize a MessageFacility message to the output.
virtual void flush() override
Flush any text in the ostream buffer to disk.
Configuration parameters for ELMultiFileOutput.
fhicl::Atom< bool > useApplication
"use_application" (Default: true): Use the application field when generating log file names ...
fhicl::Atom< bool > useModule
"use_module" (Default: false): Use the module field when generating log file names ...
fhicl::TableFragment< ELdestination::Config > elDestConfig
ELdestination common config parameters.