MessageLoggerQ.cc
Go to the documentation of this file.
5 
6 #include <cstring>
7 #include <iostream>
8 
9 using namespace mf;
10 using namespace mf::service;
11 
12 namespace {
13 
14  class StandAloneScribe : public AbstractMLscribe {
15  public:
16  StandAloneScribe() = default;
17  StandAloneScribe(StandAloneScribe const&) = delete;
18  StandAloneScribe& operator=(StandAloneScribe const&) = delete;
19 
20  void runCommand(OpCode opcode, void* operand) override;
21  };
22 
23  void
24  StandAloneScribe::runCommand(OpCode const opcode, void* const operand)
25  {
26  // even though we don't print, have to clean up memory
27  switch (opcode) {
28  case LOG_A_MESSAGE: {
29  mf::ErrorObj* errorobj_p = static_cast<mf::ErrorObj*>(operand);
30  if (MessageLoggerQ::ignore(errorobj_p->xid().severity(),
31  errorobj_p->xid().id())) {
32  delete errorobj_p;
33  break;
34  }
35  if (errorobj_p->is_verbatim()) {
36  std::cerr << errorobj_p->fullText() << std::endl;
37  } else {
38  std::cerr << "%MSG" << errorobj_p->xid().severity().getSymbol() << " "
39  << errorobj_p->xid().id() << ": \n"
40  << errorobj_p->fullText() << "\n"
41  << "%MSG" << std::endl;
42  }
43  delete errorobj_p;
44  break;
45  }
46  default:
47  break;
48  }
49  }
50 
51  std::unique_ptr<StandAloneScribe>
52  obtainStandAloneScribePtr()
53  {
54  static auto standAloneScribe_ptr = std::make_unique<StandAloneScribe>();
55  return std::move(standAloneScribe_ptr);
56  }
57 
58 } // end of anonymous namespace
59 
60 std::unique_ptr<AbstractMLscribe> MessageLoggerQ::mlscribe_ptr =
61  obtainStandAloneScribePtr();
62 
65 {
66  static MessageLoggerQ queue;
67  return &queue;
68 }
69 void
70 MessageLoggerQ::setMLscribe_ptr(std::unique_ptr<AbstractMLscribe> m)
71 {
72  if (!m) {
73  mlscribe_ptr = obtainStandAloneScribePtr();
74  } else {
75  mlscribe_ptr = std::move(m);
76  }
77 }
78 
79 void
80 MessageLoggerQ::simpleCommand(OpCode const opcode, void* operand)
81 {
82  mlscribe_ptr->runCommand(opcode, operand);
83 }
84 
85 void
87  void* operand,
88  std::string const& commandMnemonic) try {
89  mlscribe_ptr->runCommand(opcode, operand);
90 }
91 catch (mf::Exception const& ex) {
93  "Exception from MessageLoggerQ::" + commandMnemonic,
94  ex);
95 } // handshakedCommand
96 
97 void
99 {
100  simpleCommand(END_THREAD, nullptr);
101 }
102 
103 void
105 {
106  simpleCommand(SHUT_UP, nullptr);
107 }
108 
109 void
111 {
112  simpleCommand(LOG_A_MESSAGE, static_cast<void*>(p));
113 }
114 
115 void
117 {
118  handshakedCommand(CONFIGURE, p, "CFG");
119 }
120 
121 void
123 {
124  simpleCommand(SUMMARIZE, nullptr);
125 }
126 
127 void
129 {
130  handshakedCommand(FLUSH_LOG_Q, nullptr, "FLS");
131 }
132 
134 std::set<std::string> MessageLoggerQ::squelchSet;
135 
136 void
138 {
139  threshold = severity;
140 }
141 
142 void
144 {
145  squelchSet.insert(category);
146 }
147 
148 bool
150  std::string const& category)
151 {
152  if (severity < threshold)
153  return true;
154  if (squelchSet.count(category) > 0)
155  return true;
156  return false;
157 }
158 
159 void
161 {
162  mlscribe_ptr->setApplication(application);
163 }
164 
165 void
167 {
168  mlscribe_ptr->setHostName(hostName);
169 }
170 
171 void
173 {
174  mlscribe_ptr->setHostAddr(hostAddr);
175 }
176 
177 void
179 {
180  mlscribe_ptr->setPID(pid);
181 }
static const double m
Definition: Units.h:79
ELextendedID const & xid() const
Definition: ErrorObj.cc:44
static void MLqLOG(ErrorObj *p)
static void MLqSHT()
std::string string
Definition: nybbler.cc:12
static bool ignore(mf::ELseverityLevel severity, std::string const &category)
static void handshakedCommand(service::OpCode opcode, void *operand, std::string const &commandMnemonic)
std::string fullText() const
Definition: ErrorObj.cc:81
static void simpleCommand(service::OpCode opcode, void *operand)
static void setPID(long PID)
bool is_verbatim() const
Definition: ErrorObj.cc:69
static void MLqFLS()
cet::coded_exception< errors::error, detail::translate > Exception
Definition: exception.h:16
std::string getSymbol() const
static void MLqSUM()
ELseverityLevel severity() const
Definition: ELextendedID.h:76
static MessageLoggerQ * instance()
static void MLqEND()
static mf::ELseverityLevel threshold
static void setMLscribe_ptr(std::unique_ptr< mf::service::AbstractMLscribe > m)
std::string const & id() const
Definition: ELextendedID.h:70
static std::set< std::string > squelchSet
static void setApplication(std::string const &application)
static void MLqCFG(Config *p)
static void squelch(std::string const &category)
static void setHostAddr(std::string const &addr)
static std::unique_ptr< mf::service::AbstractMLscribe > mlscribe_ptr
static void standAloneThreshold(mf::ELseverityLevel severity)
static void setHostName(std::string const &name)