ORE Studio 0.0.4
Loading...
Searching...
No Matches
Public Member Functions | List of all members
database_sink_backend Class Reference

Boost.Log sink backend that prepares logs for database storage. More...

#include <database_sink_backend.hpp>

Inherits basic_sink_backend< boost::log::sinks::synchronized_feeding >.

Collaboration diagram for database_sink_backend:
Collaboration graph

Public Member Functions

 database_sink_backend (std::shared_ptr< domain::resource > resource, database_log_handler handler, const std::string &source_type="test", const std::string &source_name="unit-test")
 Constructs the database sink backend.
 
void consume (const boost::log::record_view &rec)
 Processes a Boost.Log record and converts it for database storage.
 
void set_session_id (const boost::uuids::uuid &session_id)
 Sets the session ID for logs produced by this sink.
 
void set_account_id (const boost::uuids::uuid &account_id)
 Sets the account ID for logs produced by this sink.
 

Detailed Description

Boost.Log sink backend that prepares logs for database storage.

This sink extracts log information from Boost.Log records and converts them to the telemetry domain model for storage in the database. It's designed to be used primarily for unit testing scenarios where logs need to be captured in the database for inspection and validation.

The sink can be enabled/disabled via configuration and operates independently of other logging sinks (console, file, telemetry export). It accepts a handler function that performs the actual database storage, allowing for flexibility in how the data is persisted.

Usage:

auto resource = std::make_shared<domain::resource>(
domain::resource::from_environment("test-app", "1.0.0"));
auto handler = [](const domain::telemetry_log_entry& entry) {
// Store to database
};
auto backend = boost::make_shared<database_sink_backend>(resource, handler);
auto sink = boost::make_shared<
boost::log::sinks::asynchronous_sink<database_sink_backend>>(backend);
boost::log::core::get()->add_sink(sink);
static resource from_environment(std::string_view service_name, std::string_view service_version)
Creates a resource by detecting the local environment.
Definition resource.cpp:59
A persisted telemetry log entry.
Definition telemetry_log_entry.hpp:41

Constructor & Destructor Documentation

◆ database_sink_backend()

database_sink_backend ( std::shared_ptr< domain::resource resource,
database_log_handler  handler,
const std::string &  source_type = "test",
const std::string &  source_name = "unit-test" 
)
explicit

Constructs the database sink backend.

Parameters
resourceThe resource describing the entity producing logs. Shared across all log records from this source.
handlerFunction called for each converted log entry.
source_typeType of source ('client' or 'server', default: 'test').
source_nameName of the source application (default: 'unit-test').

Member Function Documentation

◆ consume()

void consume ( const boost::log::record_view &  rec)

Processes a Boost.Log record and converts it for database storage.

This method is called by Boost.Log for each log record that passes the sink's filter. It extracts all relevant attributes and creates a telemetry_log_entry for the handler to store in the database.

Parameters
recThe Boost.Log record view to process.

◆ set_session_id()

void set_session_id ( const boost::uuids::uuid &  session_id)

Sets the session ID for logs produced by this sink.

This is useful for correlating test logs with specific test sessions.

Parameters
session_idThe session UUID to associate with logs.

◆ set_account_id()

void set_account_id ( const boost::uuids::uuid &  account_id)

Sets the account ID for logs produced by this sink.

This is useful for associating test logs with specific accounts.

Parameters
account_idThe account UUID to associate with logs.