$treeview $search $mathjax $extrastylesheet
artdaq_mfextensions
v1_03_03
$projectbrief
|
$projectbrief
|
$searchbox |
00001 #include "cetlib/PluginTypeDeducer.h" 00002 #include "fhiclcpp/ParameterSet.h" 00003 00004 #include "messagefacility/MessageService/ELdestination.h" 00005 #include "messagefacility/Utilities/ELseverityLevel.h" 00006 #include "messagefacility/Utilities/exception.h" 00007 //#include "messagefacility/Utilities/formatTime.h" 00008 #include <iostream> 00009 #include "cetlib/compiler_macros.h" 00010 00011 namespace mfplugins { 00012 using mf::ELseverityLevel; 00013 using mf::ErrorObj; 00014 using mf::service::ELdestination; 00015 00019 class ELANSI : public ELdestination { 00020 struct Config { 00021 fhicl::TableFragment<ELdestination::Config> elDestConfig; 00022 fhicl::Atom<bool> bellOnError{fhicl::Name{"bell_on_error"}, 00023 fhicl::Comment{"Whether to ring the system bell on error messages"}, true}; 00024 fhicl::Atom<bool> blinkOnError{fhicl::Name{"blink_error_messages"}, 00025 fhicl::Comment{"Whether to print error messages with blinking text"}, false}; 00026 fhicl::Atom<std::string> errorColor{fhicl::Name{"error_ansi_color"}, 00027 fhicl::Comment{"ANSI Color string for Error Messages"}, "\033[1m\033[91m"}; 00028 fhicl::Atom<std::string> warningColor{fhicl::Name{"warning_ansi_color"}, 00029 fhicl::Comment{"ANSI Color string for Warning Messages"}, "\033[1m\033[93m"}; 00030 fhicl::Atom<std::string> infoColor{fhicl::Name{"info_ansi_color"}, 00031 fhicl::Comment{"ANSI Color string for Info Messages"}, "\033[92m"}; 00032 fhicl::Atom<std::string> debugColor{fhicl::Name{"debug_ansi_color"}, 00033 fhicl::Comment{"ANSI Color string for Debug Messages"}, "\033[39m"}; 00034 }; 00035 using Parameters = fhicl::WrappedTable<Config>; 00036 00037 public: 00042 ELANSI(Parameters const& pset); 00043 00049 virtual void routePayload(const std::ostringstream& o, const ErrorObj& e) override; 00050 00051 private: 00052 bool bellError_; 00053 bool blinkError_; 00054 std::string errorColor_; 00055 std::string warningColor_; 00056 std::string infoColor_; 00057 std::string debugColor_; 00058 }; 00059 00060 // END DECLARATION 00061 //====================================================================== 00062 // BEGIN IMPLEMENTATION 00063 00064 //====================================================================== 00065 // ELANSI c'tor 00066 //====================================================================== 00067 00068 ELANSI::ELANSI(Parameters const& pset) 00069 : ELdestination(pset().elDestConfig()), 00070 bellError_(pset().bellOnError()), 00071 blinkError_(pset().blinkOnError()), 00072 errorColor_(pset().errorColor()), 00073 warningColor_(pset().warningColor()), 00074 infoColor_(pset().infoColor()), 00075 debugColor_(pset().debugColor()) { 00076 // std::cout << "ANSI Plugin configured with ParameterSet: " << pset.to_string() << std::endl; 00077 } 00078 00079 //====================================================================== 00080 // Message router ( overriddes ELdestination::routePayload ) 00081 //====================================================================== 00082 void ELANSI::routePayload(const std::ostringstream& oss, const ErrorObj& msg) { 00083 const auto& xid = msg.xid(); 00084 auto level = xid.severity().getLevel(); 00085 00086 switch (level) { 00087 case mf::ELseverityLevel::ELsev_success: 00088 case mf::ELseverityLevel::ELsev_zeroSeverity: 00089 case mf::ELseverityLevel::ELsev_unspecified: 00090 std::cout << debugColor_; 00091 break; 00092 00093 case mf::ELseverityLevel::ELsev_info: 00094 std::cout << infoColor_; 00095 break; 00096 00097 case mf::ELseverityLevel::ELsev_warning: 00098 std::cout << warningColor_; 00099 break; 00100 00101 case mf::ELseverityLevel::ELsev_error: 00102 case mf::ELseverityLevel::ELsev_severe: 00103 case mf::ELseverityLevel::ELsev_highestSeverity: 00104 if (bellError_) { 00105 std::cout << "\007"; 00106 } 00107 if (blinkError_) { 00108 std::cout << "\033[5m"; 00109 } 00110 std::cout << errorColor_; 00111 break; 00112 00113 default: 00114 break; 00115 } 00116 std::cout << oss.str(); 00117 std::cout << "\033[0m" << std::endl; 00118 } 00119 } // end namespace mfplugins 00120 00121 //====================================================================== 00122 // 00123 // makePlugin function 00124 // 00125 //====================================================================== 00126 00127 #ifndef EXTERN_C_FUNC_DECLARE_START 00128 #define EXTERN_C_FUNC_DECLARE_START extern "C" { 00129 #endif 00130 00131 EXTERN_C_FUNC_DECLARE_START 00132 auto makePlugin(const std::string&, const fhicl::ParameterSet& pset) { 00133 return std::make_unique<mfplugins::ELANSI>(pset); 00134 } 00135 } 00136 00137 DEFINE_BASIC_PLUGINTYPE_FUNC(mf::service::ELdestination)