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"
8 #include "cetlib/compiler_macros.h"
13 using mf::service::ELdestination;
14 using mf::ELseverityLevel;
22 #if MESSAGEFACILITY_HEX_VERSION >= 0x20103
25 fhicl::TableFragment<ELdestination::Config> elDestConfig;
26 fhicl::Atom<bool> bellOnError{ fhicl::Name{
"bell_on_error" },fhicl::Comment{
"Whether to ring the system bell on error messages" },
true };
27 fhicl::Atom<bool> blinkOnError{ fhicl::Name{
"blink_error_messages" },fhicl::Comment{
"Whether to print error messages with blinking text"},
false };
28 fhicl::Atom<std::string> errorColor{ fhicl::Name{
"error_ansi_color" },fhicl::Comment{
"ANSI Color string for Error Messages" },
"\033[1m\033[91m" };
29 fhicl::Atom<std::string> warningColor{ fhicl::Name{
"warning_ansi_color" },fhicl::Comment{
"ANSI Color string for Warning Messages" },
"\033[1m\033[93m" };
30 fhicl::Atom<std::string> infoColor{ fhicl::Name{
"info_ansi_color" },fhicl::Comment{
"ANSI Color string for Info Messages" },
"\033[92m" };
31 fhicl::Atom<std::string> debugColor{ fhicl::Name{
"debug_ansi_color" },fhicl::Comment{
"ANSI Color string for Debug Messages" },
"\033[39m" };
33 using Parameters = fhicl::WrappedTable<Config>;
40 #if MESSAGEFACILITY_HEX_VERSION < 0x20103 // v2_01_03 is s58, pre v2_01_03 is s50
41 ELANSI(
const fhicl::ParameterSet& pset);
43 ELANSI(Parameters
const& pset);
51 virtual void routePayload(
const std::ostringstream& o,
const ErrorObj& e)
override;
56 std::string errorColor_;
57 std::string warningColor_;
58 std::string infoColor_;
59 std::string debugColor_;
71 #if MESSAGEFACILITY_HEX_VERSION < 0x20103 // v2_01_03 is s58, pre v2_01_03 is s50
74 , bellError_(pset.get<bool>(
"bell_on_error", true))
75 , blinkError_(pset.get<bool>(
"blink_error_messages", false))
76 , errorColor_(pset.get<std::string>(
"error_ansi_color",
"\033[1m\033[91m"))
77 , warningColor_(pset.get<std::string>(
"warning_ansi_color",
"\033[1m\033[93m"))
78 , infoColor_(pset.get<std::string>(
"info_ansi_color",
"\033[92m"))
79 , debugColor_(pset.get<std::string>(
"debug_ansi_color",
"\033[39m"))
82 : ELdestination(pset().elDestConfig())
83 , bellError_(pset().bellOnError())
84 , blinkError_(pset().blinkOnError())
85 , errorColor_(pset().errorColor())
86 , warningColor_(pset().warningColor())
87 , infoColor_(pset().infoColor())
88 , debugColor_(pset().debugColor())
99 const auto& xid = msg.xid();
100 auto level = xid.severity().getLevel();
104 case mf::ELseverityLevel::ELsev_success:
105 case mf::ELseverityLevel::ELsev_zeroSeverity:
106 case mf::ELseverityLevel::ELsev_unspecified:
107 std::cout << debugColor_;
110 case mf::ELseverityLevel::ELsev_info:
111 std::cout << infoColor_;
114 case mf::ELseverityLevel::ELsev_warning:
115 std::cout << warningColor_;
118 case mf::ELseverityLevel::ELsev_error:
119 case mf::ELseverityLevel::ELsev_severe:
120 case mf::ELseverityLevel::ELsev_highestSeverity:
121 if (bellError_) { std::cout <<
"\007"; }
122 if (blinkError_) { std::cout <<
"\033[5m"; }
123 std::cout << errorColor_;
128 std::cout << oss.str();
129 std::cout <<
"\033[0m" << std::endl;
139 #ifndef EXTERN_C_FUNC_DECLARE_START
140 #define EXTERN_C_FUNC_DECLARE_START extern "C" {
143 EXTERN_C_FUNC_DECLARE_START
144 auto makePlugin(
const std::string&,
145 const fhicl::ParameterSet& pset)
147 return std::make_unique<mfplugins::ELANSI>(pset);
151 DEFINE_BASIC_PLUGINTYPE_FUNC(mf::service::ELdestination)
ELANSI(const fhicl::ParameterSet &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