LCOV - code coverage report
Current view: top level - /opt/artdaq/srcs/artdaq-mfextensions/mfextensions/Destinations - ANSI_mfPlugin.cc (source / functions) Coverage Total Hit
Test: artdaq.info.cleaned Lines: 0.0 % 31 0
Test Date: 2025-09-04 00:45:34 Functions: 0.0 % 4 0

            Line data    Source code
       1              : #include "cetlib/PluginTypeDeducer.h"
       2              : #include "fhiclcpp/ParameterSet.h"
       3              : #include "fhiclcpp/types/ConfigurationTable.h"
       4              : 
       5              : #include "messagefacility/MessageService/ELdestination.h"
       6              : #include "messagefacility/Utilities/ELseverityLevel.h"
       7              : #include "messagefacility/Utilities/exception.h"
       8              : // #include "messagefacility/Utilities/formatTime.h"
       9              : #include <iostream>
      10              : #include "cetlib/compiler_macros.h"
      11              : 
      12              : namespace mfplugins {
      13              : using mf::ELseverityLevel;
      14              : using mf::ErrorObj;
      15              : using mf::service::ELdestination;
      16              : 
      17              : /// <summary>
      18              : /// Message Facility destination which colorizes the console output
      19              : /// </summary>
      20              : class ELANSI : public ELdestination
      21              : {
      22              : public:
      23              :         /**
      24              :          * \brief Configuration parameters for ELANSI
      25              :          */
      26              :         struct Config
      27              :         {
      28              :                 /// ELdestination common config parameters
      29              :                 fhicl::TableFragment<ELdestination::Config> elDestConfig;
      30              :                 /// "bell_on_error" (Default: true): Whether to ring the system bell on error messages
      31              :                 fhicl::Atom<bool> bellOnError = fhicl::Atom<bool>{
      32              :                     fhicl::Name{"bell_on_error"}, fhicl::Comment{"Whether to ring the system bell on error messages"}, true};
      33              :                 /// "blink_error_messages" (Default: false): Whether to print error messages with blinking text
      34              :                 fhicl::Atom<bool> blinkOnError =
      35              :                     fhicl::Atom<bool>{fhicl::Name{"blink_error_messages"},
      36              :                                       fhicl::Comment{"Whether to print error messages with blinking text"}, false};
      37              :                 /// "error_ansi_color" (Default: "\033[1m\033[91m"): ANSI Color string for Error Messages
      38              :                 fhicl::Atom<std::string> errorColor = fhicl::Atom<std::string>{
      39              :                     fhicl::Name{"error_ansi_color"}, fhicl::Comment{"ANSI Color string for Error Messages"}, "\033[1m\033[91m"};
      40              :                 /// "warning_ansi_color" (Default: "\033[1m\033[93m"): ANSI Color string for Warning Messages
      41              :                 fhicl::Atom<std::string> warningColor = fhicl::Atom<std::string>{
      42              :                     fhicl::Name{"warning_ansi_color"}, fhicl::Comment{"ANSI Color string for Warning Messages"}, "\033[1m\033[93m"};
      43              :                 /// "info_ansi_color" (Default: "\033[92m"): ANSI Color string for Info Messages
      44              :                 fhicl::Atom<std::string> infoColor = fhicl::Atom<std::string>{
      45              :                     fhicl::Name{"info_ansi_color"}, fhicl::Comment{"ANSI Color string for Info Messages"}, "\033[92m"};
      46              :                 /// "debug_ansi_color" (Default: "\033[39m"): ANSI Color string for ErrDebugor Messages
      47              :                 fhicl::Atom<std::string> debugColor = fhicl::Atom<std::string>{
      48              :                     fhicl::Name{"debug_ansi_color"}, fhicl::Comment{"ANSI Color string for Debug Messages"}, "\033[39m"};
      49              :         };
      50              :         /// Used for ParameterSet validation
      51              :         using Parameters = fhicl::WrappedTable<Config>;
      52              : 
      53              : public:
      54              :         /// <summary>
      55              :         /// ELANSI Constructor
      56              :         /// </summary>
      57              :         /// <param name="pset">ParameterSet used to configure ELANSI</param>
      58              :         ELANSI(Parameters const& pset);
      59              : 
      60              :         /**
      61              :          * \brief Serialize a MessageFacility message to the output
      62              :          * \param o Stringstream object containing message data
      63              :          * \param msg MessageFacility object containing header information
      64              :          */
      65              :         void routePayload(const std::ostringstream& o, const ErrorObj& msg) override;
      66              : 
      67              : private:
      68              :         bool bellError_;
      69              :         bool blinkError_;
      70              :         std::string errorColor_;
      71              :         std::string warningColor_;
      72              :         std::string infoColor_;
      73              :         std::string debugColor_;
      74              : };
      75              : 
      76              : // END DECLARATION
      77              : //======================================================================
      78              : // BEGIN IMPLEMENTATION
      79              : 
      80              : //======================================================================
      81              : // ELANSI c'tor
      82              : //======================================================================
      83              : 
      84            0 : ELANSI::ELANSI(Parameters const& pset)
      85            0 :     : ELdestination(pset().elDestConfig()), bellError_(pset().bellOnError()), blinkError_(pset().blinkOnError()), errorColor_(pset().errorColor()), warningColor_(pset().warningColor()), infoColor_(pset().infoColor()), debugColor_(pset().debugColor())
      86              : {
      87              :         // std::cout << "ANSI Plugin configured with ParameterSet: " << pset.to_string() << std::endl;
      88            0 : }
      89              : 
      90              : //======================================================================
      91              : // Message router ( overriddes ELdestination::routePayload )
      92              : //======================================================================
      93            0 : void ELANSI::routePayload(const std::ostringstream& oss, const ErrorObj& msg)
      94              : {
      95            0 :         const auto& xid = msg.xid();
      96            0 :         auto level = xid.severity().getLevel();
      97              : 
      98            0 :         switch (level)
      99              :         {
     100            0 :                 case mf::ELseverityLevel::ELsev_success:
     101              :                 case mf::ELseverityLevel::ELsev_zeroSeverity:
     102              :                 case mf::ELseverityLevel::ELsev_unspecified:
     103            0 :                         std::cout << debugColor_;
     104            0 :                         break;
     105              : 
     106            0 :                 case mf::ELseverityLevel::ELsev_info:
     107            0 :                         std::cout << infoColor_;
     108            0 :                         break;
     109              : 
     110            0 :                 case mf::ELseverityLevel::ELsev_warning:
     111            0 :                         std::cout << warningColor_;
     112            0 :                         break;
     113              : 
     114            0 :                 case mf::ELseverityLevel::ELsev_error:
     115              :                 case mf::ELseverityLevel::ELsev_severe:
     116              :                 case mf::ELseverityLevel::ELsev_highestSeverity:
     117            0 :                         if (bellError_)
     118              :                         {
     119            0 :                                 std::cout << "\007";
     120              :                         }
     121            0 :                         if (blinkError_)
     122              :                         {
     123            0 :                                 std::cout << "\033[5m";
     124              :                         }
     125            0 :                         std::cout << errorColor_;
     126            0 :                         break;
     127              : 
     128            0 :                 default:
     129            0 :                         break;
     130              :         }
     131            0 :         std::cout << oss.str();
     132            0 :         std::cout << "\033[0m" << std::endl;
     133            0 : }
     134              : }  // end namespace mfplugins
     135              : 
     136              : //======================================================================
     137              : //
     138              : // makePlugin function
     139              : //
     140              : //======================================================================
     141              : 
     142              : #ifndef EXTERN_C_FUNC_DECLARE_START
     143              : #define EXTERN_C_FUNC_DECLARE_START extern "C" {
     144              : #endif
     145              : 
     146              : EXTERN_C_FUNC_DECLARE_START
     147            0 : auto makePlugin(const std::string& /*unused*/, const fhicl::ParameterSet& pset)
     148              : {
     149            0 :         return std::make_unique<mfplugins::ELANSI>(pset);
     150              : }
     151              : }
     152              : 
     153            0 : DEFINE_BASIC_PLUGINTYPE_FUNC(mf::service::ELdestination)
        

Generated by: LCOV version 2.0-1