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 {
00017 class MsgFacilityMetric : public MetricPlugin
00018 {
00019 private:
00020 std::string facility_;
00021 int outputLevel_;
00022 public:
00023 MsgFacilityMetric(fhicl::ParameterSet config)
00024 : MetricPlugin(config)
00025 , facility_(config.get<std::string>("output_message_application_name", "ARTDAQ Metric"))
00026 , outputLevel_(0)
00027 {
00028 try
00029 {
00030 outputLevel_ = config.get<int>("output_message_severity", 0);
00031 }
00032 catch (cet::exception)
00033 {
00034 std::string levelString = config.get<std::string>("output_message_severity", "Info");
00035 if (levelString == "Info" || levelString == "info" || levelString == "LogInfo")
00036 {
00037 outputLevel_ = 0;
00038 }
00039 else if (levelString == "Debug" || levelString == "debug" || levelString == "LogDebug")
00040 {
00041 outputLevel_ = 1;
00042 }
00043 else if (levelString == "Warning" || levelString == "warning" || levelString == "LogWarning" || levelString == "Warn" || levelString == "warn")
00044 {
00045 outputLevel_ = 2;
00046 }
00047 else if (levelString == "Error" || levelString == "error" || levelString == "LogError")
00048 {
00049 outputLevel_ = 3;
00050 }
00051 }
00052 startMetrics();
00053 }
00054
00055 ~MsgFacilityMetric() { stopMetrics(); }
00056 virtual std::string getLibName() const { return "msgFacility"; }
00057
00058 virtual void sendMetric_(const std::string& name, const std::string& value, const std::string& unit)
00059 {
00060 if (!inhibit_)
00061 {
00062 switch (outputLevel_)
00063 {
00064 case 0:
00065 mf::LogInfo(facility_) << name << ": " << value << " " << unit << "." << std::endl;
00066 break;
00067 case 1:
00068 mf::LogDebug(facility_) << name << ": " << value << " " << unit << "." << std::endl;
00069 break;
00070 case 2:
00071 mf::LogWarning(facility_) << name << ": " << value << " " << unit << "." << std::endl;
00072 break;
00073 case 3:
00074 mf::LogError(facility_) << name << ": " << value << " " << unit << "." << std::endl;
00075 break;
00076 }
00077 }
00078 }
00079
00080 virtual void sendMetric_(const std::string& name, const int& value, const std::string& unit)
00081 {
00082 sendMetric(name, std::to_string(value), unit);
00083 }
00084
00085 virtual void sendMetric_(const std::string& name, const double& value, const std::string& unit)
00086 {
00087 sendMetric(name, std::to_string(value), unit);
00088 }
00089
00090 virtual void sendMetric_(const std::string& name, const float& value, const std::string& unit)
00091 {
00092 sendMetric(name, std::to_string(value), unit);
00093 }
00094
00095 virtual void sendMetric_(const std::string& name, const unsigned long int& value, const std::string& unit)
00096 {
00097 sendMetric(name, std::to_string(value), unit);
00098 }
00099
00100 virtual void startMetrics_() {}
00101 virtual void stopMetrics_() {}
00102 };
00103 }
00104
00105 DEFINE_ARTDAQ_METRIC(artdaq::MsgFacilityMetric)