1 #include "cetlib/PluginTypeDeducer.h"
2 #include "fhiclcpp/ParameterSet.h"
4 #include "messagefacility/MessageService/ELdestination.h"
5 #include "messagefacility/Utilities/ELseverityLevel.h"
6 #include "messagefacility/Utilities/exception.h"
9 #include "cetlib/compiler_macros.h"
12 using mf::ELseverityLevel;
14 using mf::service::ELdestination;
19 class ELANSI :
public ELdestination {
28 fhicl::Atom<bool>
bellOnError = fhicl::Atom<bool>{fhicl::Name{
"bell_on_error"},
29 fhicl::Comment{
"Whether to ring the system bell on error messages"},
true};
32 fhicl::Atom<bool>{fhicl::Name{
"blink_error_messages"},
33 fhicl::Comment{
"Whether to print error messages with blinking text"},
false};
35 fhicl::Atom<std::string>
errorColor=fhicl::Atom<std::string>{fhicl::Name{
"error_ansi_color"}, fhicl::Comment{
"ANSI Color string for Error Messages"},
"\033[1m\033[91m"};
38 fhicl::Name{
"warning_ansi_color"}, fhicl::Comment{
"ANSI Color string for Warning Messages"},
"\033[1m\033[93m"};
40 fhicl::Atom<std::string>
infoColor = fhicl::Atom<std::string>{
41 fhicl::Name{
"info_ansi_color"}, fhicl::Comment{
"ANSI Color string for Info Messages"},
"\033[92m"};
43 fhicl::Atom<std::string>
debugColor = fhicl::Atom<std::string>{
44 fhicl::Name{
"debug_ansi_color"},
45 fhicl::Comment{
"ANSI Color string for Debug Messages"},
"\033[39m"};
62 virtual void routePayload(
const std::ostringstream& o,
const ErrorObj& e)
override;
67 std::string errorColor_;
68 std::string warningColor_;
69 std::string infoColor_;
70 std::string debugColor_;
82 : ELdestination(pset().elDestConfig()),
83 bellError_(pset().bellOnError()),
84 blinkError_(pset().blinkOnError()),
85 errorColor_(pset().errorColor()),
86 warningColor_(pset().warningColor()),
87 infoColor_(pset().infoColor()),
88 debugColor_(pset().debugColor()) {
96 const auto& xid = msg.xid();
97 auto level = xid.severity().getLevel();
100 case mf::ELseverityLevel::ELsev_success:
101 case mf::ELseverityLevel::ELsev_zeroSeverity:
102 case mf::ELseverityLevel::ELsev_unspecified:
103 std::cout << debugColor_;
106 case mf::ELseverityLevel::ELsev_info:
107 std::cout << infoColor_;
110 case mf::ELseverityLevel::ELsev_warning:
111 std::cout << warningColor_;
114 case mf::ELseverityLevel::ELsev_error:
115 case mf::ELseverityLevel::ELsev_severe:
116 case mf::ELseverityLevel::ELsev_highestSeverity:
121 std::cout <<
"\033[5m";
123 std::cout << errorColor_;
129 std::cout << oss.str();
130 std::cout <<
"\033[0m" << std::endl;
140 #ifndef EXTERN_C_FUNC_DECLARE_START
141 #define EXTERN_C_FUNC_DECLARE_START extern "C" {
144 EXTERN_C_FUNC_DECLARE_START
145 auto makePlugin(
const std::string&,
const fhicl::ParameterSet& pset) {
146 return std::make_unique<mfplugins::ELANSI>(pset);
150 DEFINE_BASIC_PLUGINTYPE_FUNC(mf::service::ELdestination)
ELANSI(Parameters const &pset)
ELANSI Constructor
Configuration parameters for ELANSI.
virtual void routePayload(const std::ostringstream &o, const ErrorObj &e) override
Serialize a MessageFacility message to the output.
fhicl::Atom< std::string > debugColor
"debug_ansi_color" (Default: "\033[39m"): ANSI Color string for ErrDebugor Messages ...
fhicl::Atom< std::string > errorColor
"error_ansi_color" (Default: "\033[1m\033[91m"): ANSI Color string for Error Messages ...
fhicl::Atom< bool > bellOnError
"bell_on_error" (Default: true): Whether to ring the system bell on error messages ...
fhicl::TableFragment< ELdestination::Config > elDestConfig
ELdestination common config parameters.
Message Facility destination which colorizes the console output
fhicl::Atom< bool > blinkOnError
"blink_error_messages" (Default: false): Whether to print error messages with blinking text ...
fhicl::Atom< std::string > infoColor
"info_ansi_color" (Default: "\033[92m"): ANSI Color string for Info Messages
fhicl::Atom< std::string > warningColor
"warning_ansi_color" (Default: "\033[1m\033[93m"): ANSI Color string for Warning Messages ...
fhicl::WrappedTable< Config > Parameters
Used for ParameterSet validation.