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>;
36 #if MESSAGEFACILITY_HEX_VERSION < 0x20103 // v2_01_03 is s58, pre v2_01_03 is s50
37 ELANSI(
const fhicl::ParameterSet& pset);
39 ELANSI(Parameters
const& pset);
42 virtual void routePayload(
const std::ostringstream&,
const ErrorObj&)
override;
47 std::string errorColor_;
48 std::string warningColor_;
49 std::string infoColor_;
50 std::string debugColor_;
62 #if MESSAGEFACILITY_HEX_VERSION < 0x20103 // v2_01_03 is s58, pre v2_01_03 is s50
63 ELANSI::ELANSI(
const fhicl::ParameterSet& pset)
65 , bellError_(pset.get<bool>(
"bell_on_error", true))
66 , blinkError_(pset.get<bool>(
"blink_error_messages", false))
67 , errorColor_(pset.get<std::string>(
"error_ansi_color",
"\033[1m\033[91m"))
68 , warningColor_(pset.get<std::string>(
"warning_ansi_color",
"\033[1m\033[93m"))
69 , infoColor_(pset.get<std::string>(
"info_ansi_color",
"\033[92m"))
70 , debugColor_(pset.get<std::string>(
"debug_ansi_color",
"\033[39m"))
73 : ELdestination(pset().elDestConfig())
74 , bellError_(pset().bellOnError())
75 , blinkError_(pset().blinkOnError())
76 , errorColor_(pset().errorColor())
77 , warningColor_(pset().warningColor())
78 , infoColor_(pset().infoColor())
79 , debugColor_(pset().debugColor())
88 void ELANSI::routePayload(
const std::ostringstream& oss,
const ErrorObj& msg)
90 const auto& xid = msg.xid();
91 auto level = xid.severity().getLevel();
95 case mf::ELseverityLevel::ELsev_success:
96 case mf::ELseverityLevel::ELsev_zeroSeverity:
97 case mf::ELseverityLevel::ELsev_unspecified:
98 std::cout << debugColor_;
101 case mf::ELseverityLevel::ELsev_info:
102 std::cout << infoColor_;
105 case mf::ELseverityLevel::ELsev_warning:
106 std::cout << warningColor_;
109 case mf::ELseverityLevel::ELsev_error:
110 case mf::ELseverityLevel::ELsev_severe:
111 case mf::ELseverityLevel::ELsev_highestSeverity:
112 if (bellError_) { std::cout <<
"\007"; }
113 if (blinkError_) { std::cout <<
"\033[5m"; }
114 std::cout << errorColor_;
119 std::cout << oss.str();
120 std::cout <<
"\033[0m" << std::endl;
130 #ifndef EXTERN_C_FUNC_DECLARE_START
131 #define EXTERN_C_FUNC_DECLARE_START extern "C" {
134 EXTERN_C_FUNC_DECLARE_START
135 auto makePlugin(
const std::string&,
136 const fhicl::ParameterSet& pset)
138 return std::make_unique<mfplugins::ELANSI>(pset);
142 DEFINE_BASIC_PLUGINTYPE_FUNC(mf::service::ELdestination)
Message Facility destination which colorizes the console output