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 public:
00029
00030 ELANSI(const fhicl::ParameterSet& pset);
00031
00032 # if MESSAGEFACILITY_HEX_VERSION >= 0x20002 // an indication of a switch from s48 to s50
00033 virtual void routePayload(const std::ostringstream&, const ErrorObj&) override;
00034 # else
00035 virtual void routePayload(const std::ostringstream&, const ErrorObj&, const ELcontextSupplier&) override;
00036 # endif
00037
00038 private:
00039 bool bellError_;
00040 bool blinkError_;
00041 std::string errorColor_;
00042 std::string warningColor_;
00043 std::string infoColor_;
00044 std::string debugColor_;
00045 };
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 ELANSI::ELANSI(const fhicl::ParameterSet& pset)
00057 : ELdestination(pset)
00058 , bellError_(pset.get<bool>("bell_on_error", true))
00059 , blinkError_(pset.get<bool>("blink_error_messages", false))
00060 , errorColor_(pset.get<std::string>("error_ansi_color", "\033[1m\033[91m"))
00061 , warningColor_(pset.get<std::string>("warning_ansi_color", "\033[1m\033[93m"))
00062 , infoColor_(pset.get<std::string>("info_ansi_color", "\033[92m"))
00063 , debugColor_(pset.get<std::string>("debug_ansi_color", "\033[39m"))
00064 {
00065
00066 }
00067
00068
00069
00070
00071 void ELANSI::routePayload(const std::ostringstream& oss, const ErrorObj& msg
00072 # if MESSAGEFACILITY_HEX_VERSION < 0x20002
00073 , ELcontextSupplier const&
00074 # endif
00075 )
00076 {
00077 const auto& xid = msg.xid();
00078 # if MESSAGEFACILITY_HEX_VERSION >= 0x20002 // an indication of a switch from s48 to s50
00079 auto level = xid.severity().getLevel();
00080 # else
00081 auto level = xid.severity.getLevel();
00082 # endif
00083
00084 switch (level)
00085 {
00086 # if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
00087 case mf::ELseverityLevel::ELsev_incidental:
00088 # endif
00089 case mf::ELseverityLevel::ELsev_success:
00090 case mf::ELseverityLevel::ELsev_zeroSeverity:
00091 case mf::ELseverityLevel::ELsev_unspecified:
00092 std::cout << debugColor_;
00093 break;
00094
00095 case mf::ELseverityLevel::ELsev_info:
00096 std::cout << infoColor_;
00097 break;
00098
00099 case mf::ELseverityLevel::ELsev_warning:
00100 # if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
00101 case mf::ELseverityLevel::ELsev_warning2:
00102 # endif
00103 std::cout << warningColor_;
00104 break;
00105
00106 case mf::ELseverityLevel::ELsev_error:
00107 # if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
00108 case mf::ELseverityLevel::ELsev_error2:
00109 case mf::ELseverityLevel::ELsev_next:
00110 case mf::ELseverityLevel::ELsev_severe2:
00111 case mf::ELseverityLevel::ELsev_abort:
00112 case mf::ELseverityLevel::ELsev_fatal:
00113 # endif
00114 case mf::ELseverityLevel::ELsev_severe:
00115 case mf::ELseverityLevel::ELsev_highestSeverity:
00116 if (bellError_) { std::cout << "\007"; }
00117 if (blinkError_) { std::cout << "\033[5m"; }
00118 std::cout << errorColor_;
00119 break;
00120
00121 default: break;
00122 }
00123 std::cout << oss.str();
00124 std::cout << "\033[0m" << std::endl;
00125 }
00126 }
00127
00128
00129
00130
00131
00132
00133
00134 extern "C"
00135 {
00136 auto makePlugin(const std::string&,
00137 const fhicl::ParameterSet& pset)
00138 {
00139 return std::make_unique<mfplugins::ELANSI>(pset);
00140 }
00141 }
00142
00143 DEFINE_BASIC_PLUGINTYPE_FUNC(mf::service::ELdestination)