00001
00002
00003
00004
00005
00006
00007 #include "artdaq-utilities/Plugins/MetricMacros.hh"
00008 #include "fhiclcpp/ParameterSet.h"
00009 #include "messagefacility/MessageLogger/MessageLogger.h"
00010
00011 #include <iostream>
00012 #include <string>
00013 #include <algorithm>
00014
00015 namespace artdaq
00016 {
00020 class MsgFacilityMetric : public MetricPlugin
00021 {
00022 private:
00023 std::string facility_;
00024 int outputLevel_;
00025 public:
00039 explicit MsgFacilityMetric(fhicl::ParameterSet const& config, std::string const& app_name)
00040 : MetricPlugin(config, app_name)
00041 , facility_(config.get<std::string>("output_message_category_name", "ARTDAQ Metric"))
00042 , outputLevel_(0)
00043 {
00044 try
00045 {
00046 outputLevel_ = config.get<int>("output_message_severity", 0);
00047 }
00048 catch (cet::exception)
00049 {
00050 std::string levelString = config.get<std::string>("output_message_severity", "Info");
00051 if (levelString == "Info" || levelString == "info" || levelString == "LogInfo")
00052 {
00053 outputLevel_ = 0;
00054 }
00055 else if (levelString == "Debug" || levelString == "debug" || levelString == "LogDebug")
00056 {
00057 outputLevel_ = 1;
00058 }
00059 else if (levelString == "Warning" || levelString == "warning" || levelString == "LogWarning" || levelString == "Warn" || levelString == "warn")
00060 {
00061 outputLevel_ = 2;
00062 }
00063 else if (levelString == "Error" || levelString == "error" || levelString == "LogError")
00064 {
00065 outputLevel_ = 3;
00066 }
00067 }
00068 startMetrics();
00069 }
00070
00074 virtual ~MsgFacilityMetric() { stopMetrics(); }
00079 std::string getLibName() const override { return "msgFacility"; }
00080
00087 void sendMetric_(const std::string& name, const std::string& value, const std::string& unit) override
00088 {
00089 if (!inhibit_)
00090 {
00091 switch (outputLevel_)
00092 {
00093 case 0:
00094 mf::LogInfo(facility_) << name << ": " << value << " " << unit << "." << std::endl;
00095 break;
00096 case 1:
00097 mf::LogDebug(facility_) << name << ": " << value << " " << unit << "." << std::endl;
00098 break;
00099 case 2:
00100 mf::LogWarning(facility_) << name << ": " << value << " " << unit << "." << std::endl;
00101 break;
00102 case 3:
00103 mf::LogError(facility_) << name << ": " << value << " " << unit << "." << std::endl;
00104 break;
00105 }
00106 }
00107 }
00108
00115 void sendMetric_(const std::string& name, const int& value, const std::string& unit) override
00116 {
00117 sendMetric_(name, std::to_string(value), unit);
00118 }
00119
00126 void sendMetric_(const std::string& name, const double& value, const std::string& unit) override
00127 {
00128 sendMetric_(name, std::to_string(value), unit);
00129 }
00130
00137 void sendMetric_(const std::string& name, const float& value, const std::string& unit) override
00138 {
00139 sendMetric_(name, std::to_string(value), unit);
00140 }
00141
00148 void sendMetric_(const std::string& name, const unsigned long int& value, const std::string& unit) override
00149 {
00150 sendMetric_(name, std::to_string(value), unit);
00151 }
00152
00156 void startMetrics_() override {}
00160 void stopMetrics_() override {}
00161 };
00162 }
00163
00164 DEFINE_ARTDAQ_METRIC(artdaq::MsgFacilityMetric)