00001 #include "cetlib/PluginTypeDeducer.h"
00002 #include "fhiclcpp/ParameterSet.h"
00003
00004 #include "messagefacility/MessageService/ELdestination.h"
00005 #include "messagefacility/Utilities/ELseverityLevel.h"
00006 #if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
00007 # include "messagefacility/MessageLogger/MessageDrop.h"
00008 # include "messagefacility/MessageService/ELcontextSupplier.h"
00009 #endif
00010 #include "messagefacility/Utilities/exception.h"
00011 #include "messagefacility/Utilities/formatTime.h"
00012 #include <iostream>
00013
00014 namespace mfplugins
00015 {
00016 using mf::service::ELdestination;
00017 using mf::ELseverityLevel;
00018 #if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
00019 using mf::service::ELcontextSupplier;
00020 #endif
00021 using mf::ErrorObj;
00022
00026 class ELANSI : public ELdestination
00027 {
00028 #if MESSAGEFACILITY_HEX_VERSION >= 0x20103
00029 struct Config
00030 {
00031 fhicl::TableFragment<ELdestination::Config> elDestConfig;
00032 fhicl::Atom<bool> bellOnError{ fhicl::Name{ "bell_on_error" },fhicl::Comment{ "Whether to ring the system bell on error messages" },true };
00033 fhicl::Atom<bool> blinkOnError{ fhicl::Name{ "blink_error_messages" },fhicl::Comment{ "Whether to print error messages with blinking text"},false };
00034 fhicl::Atom<std::string> errorColor{ fhicl::Name{ "error_ansi_color" },fhicl::Comment{ "ANSI Color string for Error Messages" }, "\033[1m\033[91m" };
00035 fhicl::Atom<std::string> warningColor{ fhicl::Name{ "warning_ansi_color" },fhicl::Comment{ "ANSI Color string for Warning Messages" }, "\033[1m\033[93m" };
00036 fhicl::Atom<std::string> infoColor{ fhicl::Name{ "info_ansi_color" },fhicl::Comment{ "ANSI Color string for Info Messages" }, "\033[92m" };
00037 fhicl::Atom<std::string> debugColor{ fhicl::Name{ "debug_ansi_color" },fhicl::Comment{ "ANSI Color string for Debug Messages" }, "\033[39m" };
00038 };
00039 using Parameters = fhicl::WrappedTable<Config>;
00040 #endif
00041 public:
00042 #if MESSAGEFACILITY_HEX_VERSION < 0x20103 // v2_01_03 is s58, pre v2_01_03 is s50
00043 ELANSI(const fhicl::ParameterSet& pset);
00044 #else
00045 ELANSI(Parameters const& pset);
00046 #endif
00047
00048 # if MESSAGEFACILITY_HEX_VERSION >= 0x20002 // an indication of a switch from s48 to s50
00049 virtual void routePayload(const std::ostringstream&, const ErrorObj&) override;
00050 # else
00051 virtual void routePayload(const std::ostringstream&, const ErrorObj&, const ELcontextSupplier&) override;
00052 # endif
00053
00054 private:
00055 bool bellError_;
00056 bool blinkError_;
00057 std::string errorColor_;
00058 std::string warningColor_;
00059 std::string infoColor_;
00060 std::string debugColor_;
00061 };
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 #if MESSAGEFACILITY_HEX_VERSION < 0x20103 // v2_01_03 is s58, pre v2_01_03 is s50
00073 ELANSI::ELANSI(const fhicl::ParameterSet& pset)
00074 : ELdestination(pset)
00075 , bellError_(pset.get<bool>("bell_on_error", true))
00076 , blinkError_(pset.get<bool>("blink_error_messages", false))
00077 , errorColor_(pset.get<std::string>("error_ansi_color", "\033[1m\033[91m"))
00078 , warningColor_(pset.get<std::string>("warning_ansi_color", "\033[1m\033[93m"))
00079 , infoColor_(pset.get<std::string>("info_ansi_color", "\033[92m"))
00080 , debugColor_(pset.get<std::string>("debug_ansi_color", "\033[39m"))
00081 #else
00082 ELANSI::ELANSI(Parameters const& pset)
00083 : ELdestination(pset().elDestConfig())
00084 , bellError_(pset().bellOnError())
00085 , blinkError_(pset().blinkOnError())
00086 , errorColor_(pset().errorColor())
00087 , warningColor_(pset().warningColor())
00088 , infoColor_(pset().infoColor())
00089 , debugColor_(pset().debugColor())
00090 #endif
00091 {
00092
00093 }
00094
00095
00096
00097
00098 void ELANSI::routePayload(const std::ostringstream& oss, const ErrorObj& msg
00099 # if MESSAGEFACILITY_HEX_VERSION < 0x20002
00100 , ELcontextSupplier const&
00101 # endif
00102 )
00103 {
00104 const auto& xid = msg.xid();
00105 # if MESSAGEFACILITY_HEX_VERSION >= 0x20002 // an indication of a switch from s48 to s50
00106 auto level = xid.severity().getLevel();
00107 # else
00108 auto level = xid.severity.getLevel();
00109 # endif
00110
00111 switch (level)
00112 {
00113 # if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
00114 case mf::ELseverityLevel::ELsev_incidental:
00115 # endif
00116 case mf::ELseverityLevel::ELsev_success:
00117 case mf::ELseverityLevel::ELsev_zeroSeverity:
00118 case mf::ELseverityLevel::ELsev_unspecified:
00119 std::cout << debugColor_;
00120 break;
00121
00122 case mf::ELseverityLevel::ELsev_info:
00123 std::cout << infoColor_;
00124 break;
00125
00126 case mf::ELseverityLevel::ELsev_warning:
00127 # if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
00128 case mf::ELseverityLevel::ELsev_warning2:
00129 # endif
00130 std::cout << warningColor_;
00131 break;
00132
00133 case mf::ELseverityLevel::ELsev_error:
00134 # if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
00135 case mf::ELseverityLevel::ELsev_error2:
00136 case mf::ELseverityLevel::ELsev_next:
00137 case mf::ELseverityLevel::ELsev_severe2:
00138 case mf::ELseverityLevel::ELsev_abort:
00139 case mf::ELseverityLevel::ELsev_fatal:
00140 # endif
00141 case mf::ELseverityLevel::ELsev_severe:
00142 case mf::ELseverityLevel::ELsev_highestSeverity:
00143 if (bellError_) { std::cout << "\007"; }
00144 if (blinkError_) { std::cout << "\033[5m"; }
00145 std::cout << errorColor_;
00146 break;
00147
00148 default: break;
00149 }
00150 std::cout << oss.str();
00151 std::cout << "\033[0m" << std::endl;
00152 }
00153 }
00154
00155
00156
00157
00158
00159
00160
00161 extern "C"
00162 {
00163 auto makePlugin(const std::string&,
00164 const fhicl::ParameterSet& pset)
00165 {
00166 return std::make_unique<mfplugins::ELANSI>(pset);
00167 }
00168 }
00169
00170 DEFINE_BASIC_PLUGINTYPE_FUNC(mf::service::ELdestination)