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"
12 #include "cetlib/compiler_macros.h"
17 using mf::service::ELdestination;
18 using mf::ELseverityLevel;
19 #if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
20 using mf::service::ELcontextSupplier;
29 #if MESSAGEFACILITY_HEX_VERSION >= 0x20103
32 fhicl::TableFragment<ELdestination::Config> elDestConfig;
33 fhicl::Atom<bool> bellOnError{ fhicl::Name{
"bell_on_error" },fhicl::Comment{
"Whether to ring the system bell on error messages" },
true };
34 fhicl::Atom<bool> blinkOnError{ fhicl::Name{
"blink_error_messages" },fhicl::Comment{
"Whether to print error messages with blinking text"},
false };
35 fhicl::Atom<std::string> errorColor{ fhicl::Name{
"error_ansi_color" },fhicl::Comment{
"ANSI Color string for Error Messages" },
"\033[1m\033[91m" };
36 fhicl::Atom<std::string> warningColor{ fhicl::Name{
"warning_ansi_color" },fhicl::Comment{
"ANSI Color string for Warning Messages" },
"\033[1m\033[93m" };
37 fhicl::Atom<std::string> infoColor{ fhicl::Name{
"info_ansi_color" },fhicl::Comment{
"ANSI Color string for Info Messages" },
"\033[92m" };
38 fhicl::Atom<std::string> debugColor{ fhicl::Name{
"debug_ansi_color" },fhicl::Comment{
"ANSI Color string for Debug Messages" },
"\033[39m" };
40 using Parameters = fhicl::WrappedTable<Config>;
43 #if MESSAGEFACILITY_HEX_VERSION < 0x20103 // v2_01_03 is s58, pre v2_01_03 is s50
44 ELANSI(
const fhicl::ParameterSet& pset);
46 ELANSI(Parameters
const& pset);
49 # if MESSAGEFACILITY_HEX_VERSION >= 0x20002 // an indication of a switch from s48 to s50
50 virtual void routePayload(
const std::ostringstream&,
const ErrorObj&)
override;
52 virtual void routePayload(
const std::ostringstream&,
const ErrorObj&,
const ELcontextSupplier&)
override;
58 std::string errorColor_;
59 std::string warningColor_;
60 std::string infoColor_;
61 std::string debugColor_;
73 #if MESSAGEFACILITY_HEX_VERSION < 0x20103 // v2_01_03 is s58, pre v2_01_03 is s50
74 ELANSI::ELANSI(
const fhicl::ParameterSet& pset)
76 , bellError_(pset.get<bool>(
"bell_on_error", true))
77 , blinkError_(pset.get<bool>(
"blink_error_messages", false))
78 , errorColor_(pset.get<std::string>(
"error_ansi_color",
"\033[1m\033[91m"))
79 , warningColor_(pset.get<std::string>(
"warning_ansi_color",
"\033[1m\033[93m"))
80 , infoColor_(pset.get<std::string>(
"info_ansi_color",
"\033[92m"))
81 , debugColor_(pset.get<std::string>(
"debug_ansi_color",
"\033[39m"))
84 : ELdestination(pset().elDestConfig())
85 , bellError_(pset().bellOnError())
86 , blinkError_(pset().blinkOnError())
87 , errorColor_(pset().errorColor())
88 , warningColor_(pset().warningColor())
89 , infoColor_(pset().infoColor())
90 , debugColor_(pset().debugColor())
99 void ELANSI::routePayload(
const std::ostringstream& oss,
const ErrorObj& msg
100 #
if MESSAGEFACILITY_HEX_VERSION < 0x20002
101 , ELcontextSupplier
const&
105 const auto& xid = msg.xid();
106 # if MESSAGEFACILITY_HEX_VERSION >= 0x20002 // an indication of a switch from s48 to s50
107 auto level = xid.severity().getLevel();
109 auto level = xid.severity.getLevel();
114 # if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
115 case mf::ELseverityLevel::ELsev_incidental:
117 case mf::ELseverityLevel::ELsev_success:
118 case mf::ELseverityLevel::ELsev_zeroSeverity:
119 case mf::ELseverityLevel::ELsev_unspecified:
120 std::cout << debugColor_;
123 case mf::ELseverityLevel::ELsev_info:
124 std::cout << infoColor_;
127 case mf::ELseverityLevel::ELsev_warning:
128 # if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
129 case mf::ELseverityLevel::ELsev_warning2:
131 std::cout << warningColor_;
134 case mf::ELseverityLevel::ELsev_error:
135 # if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
136 case mf::ELseverityLevel::ELsev_error2:
137 case mf::ELseverityLevel::ELsev_next:
138 case mf::ELseverityLevel::ELsev_severe2:
139 case mf::ELseverityLevel::ELsev_abort:
140 case mf::ELseverityLevel::ELsev_fatal:
142 case mf::ELseverityLevel::ELsev_severe:
143 case mf::ELseverityLevel::ELsev_highestSeverity:
144 if (bellError_) { std::cout <<
"\007"; }
145 if (blinkError_) { std::cout <<
"\033[5m"; }
146 std::cout << errorColor_;
151 std::cout << oss.str();
152 std::cout <<
"\033[0m" << std::endl;
162 #ifndef EXTERN_C_FUNC_DECLARE_START
163 #define EXTERN_C_FUNC_DECLARE_START extern "C" {
166 EXTERN_C_FUNC_DECLARE_START
167 auto makePlugin(
const std::string&,
168 const fhicl::ParameterSet& pset)
170 return std::make_unique<mfplugins::ELANSI>(pset);
174 DEFINE_BASIC_PLUGINTYPE_FUNC(mf::service::ELdestination)
Message Facility destination which colorizes the console output