ifw-daq 3.1.0
IFW Data Acquisition modules
Loading...
Searching...
No Matches
eventLogObserver.cpp
Go to the documentation of this file.
1/**
2 * @file
3 * @ingroup daq_common_libdaq
4 * @copyright 2022 ESO - European Southern Observatory
5 *
6 * @brief Contains definitions for EventLogObserverLogger
7 */
9#include <fmt/format.h>
10#include <log4cplus/loggingmacros.h>
11
12namespace {
13template <class>
14inline constexpr bool always_false_v = false; // NOLINT
15}
16
17namespace daq {
18
20 : m_logger(std::move(logger)) {
21}
22
23/**
24 * Observer callback that immediately logs the event.
25 */
27 char const* preamble = "[DAQ EVENT]";
28 std::visit(
29 [&](auto const& ev) {
30 using T = std::decay_t<decltype(ev)>;
31 if constexpr (std::is_same_v<T, UserActionEvent>) {
32 auto const& ev = std::get<UserActionEvent>(event);
33 LOG4CPLUS_INFO(m_logger,
34 fmt::format("{} id='{}', type=UserActionEvent, description='{}'",
35 preamble,
36 ev.id,
37 ev.description));
38 return;
39 } else if constexpr (std::is_same_v<T, ActionEvent>) {
40 auto const& ev = std::get<ActionEvent>(event);
41 LOG4CPLUS_INFO(m_logger,
42 fmt::format("{} id='{}', type=ActionEvent, description='{}'",
43 preamble,
44 ev.id,
45 ev.description));
46 return;
47 } else if constexpr (std::is_same_v<T, GenericEvent>) {
48 auto const& ev = std::get<GenericEvent>(event);
49 LOG4CPLUS_INFO(m_logger,
50 fmt::format("{} id='{}', type=GenericEvent, description='{}'",
51 preamble,
52 ev.id,
53 ev.description));
54 return;
55 } else if constexpr (std::is_same_v<T, ErrorEvent>) {
56 auto const& ev = std::get<ErrorEvent>(event);
57 LOG4CPLUS_INFO(m_logger,
58 fmt::format("{} id='{}', type=ErrorEvent, origin='{}', "
59 "description='{}'",
60 preamble,
61 ev.id,
62 ev.origin,
63 ev.description));
64 return;
65 } else {
66 static_assert(always_false_v<T>, "non-exhaustive visitor!");
67 }
68 },
69 event);
70}
71
72} // namespace daq
EventLogObserverLogger(log4cplus::Logger logger)
void operator()(EventLog::EventType const &event) noexcept
Observer callback that immediately logs the event.
Contains declaration for EventLogObserverLogger.
std::variant< ActionEvent, UserActionEvent, GenericEvent, ErrorEvent > EventType
Definition: eventLog.hpp:90