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;
30 ELANSI(
const fhicl::ParameterSet& pset);
32 # if MESSAGEFACILITY_HEX_VERSION >= 0x20002 // an indication of a switch from s48 to s50
33 virtual void routePayload(
const std::ostringstream&,
const ErrorObj&)
override;
35 virtual void routePayload(
const std::ostringstream&,
const ErrorObj&,
const ELcontextSupplier&)
override;
41 std::string errorColor_;
42 std::string warningColor_;
43 std::string infoColor_;
44 std::string debugColor_;
56 ELANSI::ELANSI(
const fhicl::ParameterSet& pset)
58 , bellError_(pset.get<bool>(
"bell_on_error", true))
59 , blinkError_(pset.get<bool>(
"blink_error_messages", false))
60 , errorColor_(pset.get<std::string>(
"error_ansi_color",
"\033[1m\033[91m"))
61 , warningColor_(pset.get<std::string>(
"warning_ansi_color",
"\033[1m\033[93m"))
62 , infoColor_(pset.get<std::string>(
"info_ansi_color",
"\033[92m"))
63 , debugColor_(pset.get<std::string>(
"debug_ansi_color",
"\033[39m"))
71 void ELANSI::routePayload(
const std::ostringstream& oss,
const ErrorObj& msg
72 #
if MESSAGEFACILITY_HEX_VERSION < 0x20002
73 , ELcontextSupplier
const&
77 const auto& xid = msg.xid();
78 # if MESSAGEFACILITY_HEX_VERSION >= 0x20002 // an indication of a switch from s48 to s50
79 auto level = xid.severity().getLevel();
81 auto level = xid.severity.getLevel();
86 # if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
87 case mf::ELseverityLevel::ELsev_incidental:
89 case mf::ELseverityLevel::ELsev_success:
90 case mf::ELseverityLevel::ELsev_zeroSeverity:
91 case mf::ELseverityLevel::ELsev_unspecified:
92 std::cout << debugColor_;
95 case mf::ELseverityLevel::ELsev_info:
96 std::cout << infoColor_;
99 case mf::ELseverityLevel::ELsev_warning:
100 # if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
101 case mf::ELseverityLevel::ELsev_warning2:
103 std::cout << warningColor_;
106 case mf::ELseverityLevel::ELsev_error:
107 # if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
108 case mf::ELseverityLevel::ELsev_error2:
109 case mf::ELseverityLevel::ELsev_next:
110 case mf::ELseverityLevel::ELsev_severe2:
111 case mf::ELseverityLevel::ELsev_abort:
112 case mf::ELseverityLevel::ELsev_fatal:
114 case mf::ELseverityLevel::ELsev_severe:
115 case mf::ELseverityLevel::ELsev_highestSeverity:
116 if (bellError_) { std::cout <<
"\007"; }
117 if (blinkError_) { std::cout <<
"\033[5m"; }
118 std::cout << errorColor_;
123 std::cout << oss.str();
124 std::cout <<
"\033[0m" << std::endl;
136 auto makePlugin(
const std::string&,
137 const fhicl::ParameterSet& pset)
139 return std::make_unique<mfplugins::ELANSI>(pset);
143 DEFINE_BASIC_PLUGINTYPE_FUNC(mf::service::ELdestination)
Message Facility destination which colorizes the console output