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:
00038 explicit MsgFacilityMetric(fhicl::ParameterSet config)
00039 : MetricPlugin(config)
00040 , facility_(config.get<std::string>("output_message_category_name", "ARTDAQ Metric"))
00041 , outputLevel_(0)
00042 {
00043 try
00044 {
00045 outputLevel_ = config.get<int>("output_message_severity", 0);
00046 }
00047 catch (cet::exception)
00048 {
00049 std::string levelString = config.get<std::string>("output_message_severity", "Info");
00050 if (levelString == "Info" || levelString == "info" || levelString == "LogInfo")
00051 {
00052 outputLevel_ = 0;
00053 }
00054 else if (levelString == "Debug" || levelString == "debug" || levelString == "LogDebug")
00055 {
00056 outputLevel_ = 1;
00057 }
00058 else if (levelString == "Warning" || levelString == "warning" || levelString == "LogWarning" || levelString == "Warn" || levelString == "warn")
00059 {
00060 outputLevel_ = 2;
00061 }
00062 else if (levelString == "Error" || levelString == "error" || levelString == "LogError")
00063 {
00064 outputLevel_ = 3;
00065 }
00066 }
00067 startMetrics();
00068 }
00069
00073 virtual ~MsgFacilityMetric() { stopMetrics(); }
00078 std::string getLibName() const override { return "msgFacility"; }
00079
00086 void sendMetric_(const std::string& name, const std::string& value, const std::string& unit) override
00087 {
00088 if (!inhibit_)
00089 {
00090 switch (outputLevel_)
00091 {
00092 case 0:
00093 mf::LogInfo(facility_) << name << ": " << value << " " << unit << "." << std::endl;
00094 break;
00095 case 1:
00096 mf::LogDebug(facility_) << name << ": " << value << " " << unit << "." << std::endl;
00097 break;
00098 case 2:
00099 mf::LogWarning(facility_) << name << ": " << value << " " << unit << "." << std::endl;
00100 break;
00101 case 3:
00102 mf::LogError(facility_) << name << ": " << value << " " << unit << "." << std::endl;
00103 break;
00104 }
00105 }
00106 }
00107
00114 void sendMetric_(const std::string& name, const int& value, const std::string& unit) override
00115 {
00116 sendMetric(name, std::to_string(value), unit);
00117 }
00118
00125 void sendMetric_(const std::string& name, const double& value, const std::string& unit) override
00126 {
00127 sendMetric(name, std::to_string(value), unit);
00128 }
00129
00136 void sendMetric_(const std::string& name, const float& value, const std::string& unit) override
00137 {
00138 sendMetric(name, std::to_string(value), unit);
00139 }
00140
00147 void sendMetric_(const std::string& name, const unsigned long int& value, const std::string& unit) override
00148 {
00149 sendMetric(name, std::to_string(value), unit);
00150 }
00151
00155 void startMetrics_() override {}
00159 void stopMetrics_() override {}
00160 };
00161 }
00162
00163 DEFINE_ARTDAQ_METRIC(artdaq::MsgFacilityMetric)