1 #include "cetlib/PluginTypeDeducer.h"
2 #include "fhiclcpp/ParameterSet.h"
4 #include "messagefacility/MessageService/ELdestination.h"
5 #include "messagefacility/Utilities/ELseverityLevel.h"
6 #if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
7 # include "messagefacility/MessageLogger/MessageDrop.h"
8 # include "messagefacility/MessageService/ELcontextSupplier.h"
10 #include "messagefacility/Utilities/exception.h"
11 #include "messagefacility/Utilities/formatTime.h"
16 using mf::service::ELdestination;
17 using mf::ELseverityLevel;
18 #if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
19 using mf::service::ELcontextSupplier;
28 #if MESSAGEFACILITY_HEX_VERSION >= 0x20103
31 fhicl::TableFragment<ELdestination::Config> elDestConfig;
32 fhicl::Atom<bool> bellOnError{ fhicl::Name{
"bell_on_error" },fhicl::Comment{
"Whether to ring the system bell on error messages" },
true };
33 fhicl::Atom<bool> blinkOnError{ fhicl::Name{
"blink_error_messages" },fhicl::Comment{
"Whether to print error messages with blinking text"},
false };
34 fhicl::Atom<std::string> errorColor{ fhicl::Name{
"error_ansi_color" },fhicl::Comment{
"ANSI Color string for Error Messages" },
"\033[1m\033[91m" };
35 fhicl::Atom<std::string> warningColor{ fhicl::Name{
"warning_ansi_color" },fhicl::Comment{
"ANSI Color string for Warning Messages" },
"\033[1m\033[93m" };
36 fhicl::Atom<std::string> infoColor{ fhicl::Name{
"info_ansi_color" },fhicl::Comment{
"ANSI Color string for Info Messages" },
"\033[92m" };
37 fhicl::Atom<std::string> debugColor{ fhicl::Name{
"debug_ansi_color" },fhicl::Comment{
"ANSI Color string for Debug Messages" },
"\033[39m" };
39 using Parameters = fhicl::WrappedTable<Config>;
42 #if MESSAGEFACILITY_HEX_VERSION < 0x20103 // v2_01_03 is s58, pre v2_01_03 is s50
43 ELANSI(
const fhicl::ParameterSet& pset);
45 ELANSI(Parameters
const& pset);
48 # if MESSAGEFACILITY_HEX_VERSION >= 0x20002 // an indication of a switch from s48 to s50
49 virtual void routePayload(
const std::ostringstream&,
const ErrorObj&)
override;
51 virtual void routePayload(
const std::ostringstream&,
const ErrorObj&,
const ELcontextSupplier&)
override;
57 std::string errorColor_;
58 std::string warningColor_;
59 std::string infoColor_;
60 std::string debugColor_;
72 #if MESSAGEFACILITY_HEX_VERSION < 0x20103 // v2_01_03 is s58, pre v2_01_03 is s50
73 ELANSI::ELANSI(
const fhicl::ParameterSet& pset)
75 , bellError_(pset.get<bool>(
"bell_on_error", true))
76 , blinkError_(pset.get<bool>(
"blink_error_messages", false))
77 , errorColor_(pset.get<std::string>(
"error_ansi_color",
"\033[1m\033[91m"))
78 , warningColor_(pset.get<std::string>(
"warning_ansi_color",
"\033[1m\033[93m"))
79 , infoColor_(pset.get<std::string>(
"info_ansi_color",
"\033[92m"))
80 , debugColor_(pset.get<std::string>(
"debug_ansi_color",
"\033[39m"))
83 : ELdestination(pset().elDestConfig())
84 , bellError_(pset().bellOnError())
85 , blinkError_(pset().blinkOnError())
86 , errorColor_(pset().errorColor())
87 , warningColor_(pset().warningColor())
88 , infoColor_(pset().infoColor())
89 , debugColor_(pset().debugColor())
98 void ELANSI::routePayload(
const std::ostringstream& oss,
const ErrorObj& msg
99 #
if MESSAGEFACILITY_HEX_VERSION < 0x20002
100 , ELcontextSupplier
const&
104 const auto& xid = msg.xid();
105 # if MESSAGEFACILITY_HEX_VERSION >= 0x20002 // an indication of a switch from s48 to s50
106 auto level = xid.severity().getLevel();
108 auto level = xid.severity.getLevel();
113 # if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
114 case mf::ELseverityLevel::ELsev_incidental:
116 case mf::ELseverityLevel::ELsev_success:
117 case mf::ELseverityLevel::ELsev_zeroSeverity:
118 case mf::ELseverityLevel::ELsev_unspecified:
119 std::cout << debugColor_;
122 case mf::ELseverityLevel::ELsev_info:
123 std::cout << infoColor_;
126 case mf::ELseverityLevel::ELsev_warning:
127 # if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
128 case mf::ELseverityLevel::ELsev_warning2:
130 std::cout << warningColor_;
133 case mf::ELseverityLevel::ELsev_error:
134 # if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
135 case mf::ELseverityLevel::ELsev_error2:
136 case mf::ELseverityLevel::ELsev_next:
137 case mf::ELseverityLevel::ELsev_severe2:
138 case mf::ELseverityLevel::ELsev_abort:
139 case mf::ELseverityLevel::ELsev_fatal:
141 case mf::ELseverityLevel::ELsev_severe:
142 case mf::ELseverityLevel::ELsev_highestSeverity:
143 if (bellError_) { std::cout <<
"\007"; }
144 if (blinkError_) { std::cout <<
"\033[5m"; }
145 std::cout << errorColor_;
150 std::cout << oss.str();
151 std::cout <<
"\033[0m" << std::endl;
163 auto makePlugin(
const std::string&,
164 const fhicl::ParameterSet& pset)
166 return std::make_unique<mfplugins::ELANSI>(pset);
170 DEFINE_BASIC_PLUGINTYPE_FUNC(mf::service::ELdestination)
Message Facility destination which colorizes the console output