1 #include "cetlib/PluginTypeDeducer.h"
2 #include "fhiclcpp/ParameterSet.h"
4 #include "messagefacility/MessageService/ELdestination.h"
5 #include "messagefacility/Utilities/ELseverityLevel.h"
6 #include "messagefacility/Utilities/exception.h"
9 #include "cetlib/compiler_macros.h"
12 using mf::ELseverityLevel;
14 using mf::service::ELdestination;
19 class ELANSI :
public ELdestination {
21 fhicl::TableFragment<ELdestination::Config> elDestConfig;
22 fhicl::Atom<bool> bellOnError{fhicl::Name{
"bell_on_error"},
23 fhicl::Comment{
"Whether to ring the system bell on error messages"},
true};
24 fhicl::Atom<bool> blinkOnError{fhicl::Name{
"blink_error_messages"},
25 fhicl::Comment{
"Whether to print error messages with blinking text"},
false};
26 fhicl::Atom<std::string> errorColor{fhicl::Name{
"error_ansi_color"},
27 fhicl::Comment{
"ANSI Color string for Error Messages"},
"\033[1m\033[91m"};
28 fhicl::Atom<std::string> warningColor{fhicl::Name{
"warning_ansi_color"},
29 fhicl::Comment{
"ANSI Color string for Warning Messages"},
"\033[1m\033[93m"};
30 fhicl::Atom<std::string> infoColor{fhicl::Name{
"info_ansi_color"},
31 fhicl::Comment{
"ANSI Color string for Info Messages"},
"\033[92m"};
32 fhicl::Atom<std::string> debugColor{fhicl::Name{
"debug_ansi_color"},
33 fhicl::Comment{
"ANSI Color string for Debug Messages"},
"\033[39m"};
35 using Parameters = fhicl::WrappedTable<Config>;
42 ELANSI(Parameters
const& pset);
49 virtual void routePayload(
const std::ostringstream& o,
const ErrorObj& e)
override;
54 std::string errorColor_;
55 std::string warningColor_;
56 std::string infoColor_;
57 std::string debugColor_;
69 : ELdestination(pset().elDestConfig()),
70 bellError_(pset().bellOnError()),
71 blinkError_(pset().blinkOnError()),
72 errorColor_(pset().errorColor()),
73 warningColor_(pset().warningColor()),
74 infoColor_(pset().infoColor()),
75 debugColor_(pset().debugColor()) {
83 const auto& xid = msg.xid();
84 auto level = xid.severity().getLevel();
87 case mf::ELseverityLevel::ELsev_success:
88 case mf::ELseverityLevel::ELsev_zeroSeverity:
89 case mf::ELseverityLevel::ELsev_unspecified:
90 std::cout << debugColor_;
93 case mf::ELseverityLevel::ELsev_info:
94 std::cout << infoColor_;
97 case mf::ELseverityLevel::ELsev_warning:
98 std::cout << warningColor_;
101 case mf::ELseverityLevel::ELsev_error:
102 case mf::ELseverityLevel::ELsev_severe:
103 case mf::ELseverityLevel::ELsev_highestSeverity:
108 std::cout <<
"\033[5m";
110 std::cout << errorColor_;
116 std::cout << oss.str();
117 std::cout <<
"\033[0m" << std::endl;
127 #ifndef EXTERN_C_FUNC_DECLARE_START
128 #define EXTERN_C_FUNC_DECLARE_START extern "C" {
131 EXTERN_C_FUNC_DECLARE_START
132 auto makePlugin(
const std::string&,
const fhicl::ParameterSet& pset) {
133 return std::make_unique<mfplugins::ELANSI>(pset);
137 DEFINE_BASIC_PLUGINTYPE_FUNC(mf::service::ELdestination)
ELANSI(Parameters const &pset)
ELANSI Constructor
virtual void routePayload(const std::ostringstream &o, const ErrorObj &e) override
Serialize a MessageFacility message to the output.
Message Facility destination which colorizes the console output