ORE Studio 0.0.4
Loading...
Searching...
No Matches
database_sink_backend.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2025 Marco Craveiro <marco.craveiro@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20#ifndef ORES_TELEMETRY_DATABASE_LOG_DATABASE_SINK_HPP
21#define ORES_TELEMETRY_DATABASE_LOG_DATABASE_SINK_HPP
22
23#include <memory>
24#include <string>
25#include <functional>
26#include <boost/log/sinks/basic_sink_backend.hpp>
27#include <boost/log/sinks/frontend_requirements.hpp>
28#include <boost/uuid/uuid.hpp>
29#include "ores.telemetry/domain/resource.hpp"
30#include "ores.telemetry/domain/telemetry_log_entry.hpp"
31
33
41using database_log_handler = std::function<void(const domain::telemetry_log_entry&)>;
42
70 public boost::log::sinks::basic_sink_backend<
71 boost::log::sinks::synchronized_feeding> {
72public:
82 explicit database_sink_backend(
83 std::shared_ptr<domain::resource> resource,
85 const std::string& source_type = "test",
86 const std::string& source_name = "unit-test");
87
97 void consume(const boost::log::record_view& rec);
98
106 void set_session_id(const boost::uuids::uuid& session_id);
107
115 void set_account_id(const boost::uuids::uuid& account_id);
116
117private:
118 std::shared_ptr<domain::resource> resource_;
119 database_log_handler handler_;
120 std::string source_type_;
121 std::string source_name_;
122 boost::uuids::uuid session_id_;
123 boost::uuids::uuid account_id_;
124 bool has_session_id_ = false;
125 bool has_account_id_ = false;
126};
127
128}
129
130#endif
Implements logging for ORE Studio.
Definition database_sink_backend.hpp:32
std::function< void(const domain::telemetry_log_entry &)> database_log_handler
Handler function type for processing log entries destined for database storage.
Definition database_sink_backend.hpp:41
A persisted telemetry log entry.
Definition telemetry_log_entry.hpp:41
Boost.Log sink backend that prepares logs for database storage.
Definition database_sink_backend.hpp:71
void consume(const boost::log::record_view &rec)
Processes a Boost.Log record and converts it for database storage.
Definition database_sink_backend.cpp:82
void set_session_id(const boost::uuids::uuid &session_id)
Sets the session ID for logs produced by this sink.
Definition database_sink_backend.cpp:171
void set_account_id(const boost::uuids::uuid &account_id)
Sets the account ID for logs produced by this sink.
Definition database_sink_backend.cpp:176