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"
14 using mf::service::ELdestination;
30 fhicl::Atom<std::string>
baseDir = fhicl::Atom<std::string>{
31 fhicl::Name{
"base_directory"}, fhicl::Comment{
"Directory where log files will be created"},
"/tmp"};
34 fhicl::Atom<bool>{fhicl::Name{
"append"}, fhicl::Comment{
"Append to existing log files"},
true};
37 fhicl::Name{
"use_hostname"}, fhicl::Comment{
"Use the hostname when generating log file names"},
true};
40 fhicl::Atom<bool>{fhicl::Name{
"use_application"},
41 fhicl::Comment{
"Use the application field when generating log file names"},
true};
44 fhicl::Name{
"use_category"}, fhicl::Comment{
"Use the category field when generating log file names"},
false};
47 fhicl::Name{
"use_module"}, fhicl::Comment{
"Use the module field when generating log file names"},
false};
69 void routePayload(
const std::ostringstream& oss,
const ErrorObj& msg)
override;
74 void flush()
override;
84 std::unordered_map<std::string, std::unique_ptr<cet::ostream_handle>> outputs_;
100 : ELdestination(pset().elDestConfig()), baseDir_(pset().baseDir()), append_(pset().append()), useHost_(pset().useHostname()), useApplication_(pset().useApplication()), useCategory_(pset().useCategory()), useModule_(pset().useModule()) {}
107 const auto& xid = msg.xid();
108 std::string fileName = baseDir_ +
"/";
111 fileName += xid.module() +
"-";
115 fileName += xid.id() +
"-";
119 fileName += xid.application() +
"-";
123 fileName += xid.hostname() +
"-";
125 fileName += std::to_string(xid.pid()) +
".log";
126 if (outputs_.count(fileName) == 0)
129 std::make_unique<cet::ostream_handle>(fileName.c_str(), append_ ? std::ios::app : std::ios::trunc);
131 *outputs_[fileName] << oss.str();
137 for (
auto& output : outputs_)
139 output.second->flush();
150 #ifndef EXTERN_C_FUNC_DECLARE_START
151 #define EXTERN_C_FUNC_DECLARE_START extern "C" {
154 EXTERN_C_FUNC_DECLARE_START
155 auto makePlugin(
const std::string& ,
const fhicl::ParameterSet& pset)
157 return std::make_unique<mfplugins::ELMultiFileOutput>(pset);
161 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.
void routePayload(const std::ostringstream &oss, const ErrorObj &msg) override
Serialize a MessageFacility message to the output.
~ELMultiFileOutput() override=default
Default virtual Destructor
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.