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