Common System 0.2.0
Common interfaces and patterns for system integration
Loading...
Searching...
No Matches
kcenon::common::interfaces::RegistryAuditLog Class Reference

Thread-safe audit log for registry operations. More...

#include <registry_audit_log.h>

Collaboration diagram for kcenon::common::interfaces::RegistryAuditLog:
Collaboration graph

Static Public Member Functions

static void log_event (const registry_event &event)
 Log a registry event.
 
static void log_event (registry_event &&event)
 Log a registry event (move version).
 
static std::vector< registry_eventget_events ()
 Get all logged events.
 
static std::vector< registry_eventget_events_by_action (registry_action action)
 Get events filtered by action type.
 
static std::vector< registry_eventget_events_in_range (std::chrono::system_clock::time_point start, std::chrono::system_clock::time_point end)
 Get events within a time range.
 
static size_t event_count ()
 Get the number of logged events.
 
static bool is_enabled ()
 Check if audit logging is enabled.
 
static void set_enabled (bool enabled)
 Enable or disable audit logging.
 
static void clear ()
 Clear all audit events.
 

Private Member Functions

 RegistryAuditLog ()=delete
 

Static Private Member Functions

static std::mutex & get_mutex ()
 
static std::vector< registry_event > & get_events_internal ()
 
static std::atomic< bool > & get_enabled_flag ()
 

Detailed Description

Thread-safe audit log for registry operations.

RegistryAuditLog provides a centralized, thread-safe mechanism for recording all mutations to global registries. The log is append-only to maintain integrity for security auditing.

Usage Example:

// Log a successful registration
"ILogger",
true
));
// Get all events for analysis
for (const auto& event : events) {
std::cout << to_string(event.action) << " on " << event.target_name
<< " at " << event.file << ":" << event.line << std::endl;
}
static std::vector< registry_event > get_events()
Get all logged events.
static void log_event(const registry_event &event)
Log a registry event.
std::string to_string(log_level level)
Convert log level to string.
Generic event structure for the event bus.
Definition event_bus.h:111
Represents a single audit event for registry mutations.
static constexpr source_location current(const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE()) noexcept

Definition at line 161 of file registry_audit_log.h.

Constructor & Destructor Documentation

◆ RegistryAuditLog()

kcenon::common::interfaces::RegistryAuditLog::RegistryAuditLog ( )
privatedelete

Member Function Documentation

◆ clear()

void kcenon::common::interfaces::RegistryAuditLog::clear ( )
inlinestatic

Clear all audit events.

Warning
This is a destructive operation that removes all audit history. Use with caution and ensure proper authorization.
Note
This operation is allowed even when frozen for testing purposes, but a freeze event should be logged first in production.

Definition at line 333 of file registry_audit_log.h.

333 {
334 std::lock_guard<std::mutex> lock(get_mutex());
335 get_events_internal().clear();
336}
static std::vector< registry_event > & get_events_internal()

References get_events_internal(), and get_mutex().

Here is the call graph for this function:

◆ event_count()

size_t kcenon::common::interfaces::RegistryAuditLog::event_count ( )
inlinestatic

Get the number of logged events.

Returns
Number of events in the audit log

Definition at line 320 of file registry_audit_log.h.

320 {
321 std::lock_guard<std::mutex> lock(get_mutex());
322 return get_events_internal().size();
323}

References get_events_internal(), and get_mutex().

Here is the call graph for this function:

◆ get_enabled_flag()

std::atomic< bool > & kcenon::common::interfaces::RegistryAuditLog::get_enabled_flag ( )
inlinestaticprivate

Definition at line 265 of file registry_audit_log.h.

265 {
266 static std::atomic<bool> enabled{true};
267 return enabled;
268}

Referenced by is_enabled(), and set_enabled().

Here is the caller graph for this function:

◆ get_events()

std::vector< registry_event > kcenon::common::interfaces::RegistryAuditLog::get_events ( )
inlinestatic

Get all logged events.

Returns a copy of all events in the audit log. This operation is thread-safe.

Returns
Vector of all registry events

Definition at line 288 of file registry_audit_log.h.

288 {
289 std::lock_guard<std::mutex> lock(get_mutex());
290 return get_events_internal();
291}

References get_events_internal(), and get_mutex().

Here is the call graph for this function:

◆ get_events_by_action()

std::vector< registry_event > kcenon::common::interfaces::RegistryAuditLog::get_events_by_action ( registry_action action)
inlinestatic

Get events filtered by action type.

Parameters
actionThe action type to filter by
Returns
Vector of matching registry events

Definition at line 293 of file registry_audit_log.h.

294 {
295 std::lock_guard<std::mutex> lock(get_mutex());
296
297 std::vector<registry_event> result;
298 for (const auto& event : get_events_internal()) {
299 if (event.action == action) {
300 result.push_back(event);
301 }
302 }
303 return result;
304}

References get_events_internal(), and get_mutex().

Here is the call graph for this function:

◆ get_events_in_range()

std::vector< registry_event > kcenon::common::interfaces::RegistryAuditLog::get_events_in_range ( std::chrono::system_clock::time_point start,
std::chrono::system_clock::time_point end )
inlinestatic

Get events within a time range.

Parameters
startStart of time range
endEnd of time range
Returns
Vector of events within the time range

Definition at line 306 of file registry_audit_log.h.

308 {
309 std::lock_guard<std::mutex> lock(get_mutex());
310
311 std::vector<registry_event> result;
312 for (const auto& event : get_events_internal()) {
313 if (event.timestamp >= start && event.timestamp <= end) {
314 result.push_back(event);
315 }
316 }
317 return result;
318}

References get_events_internal(), and get_mutex().

Here is the call graph for this function:

◆ get_events_internal()

std::vector< registry_event > & kcenon::common::interfaces::RegistryAuditLog::get_events_internal ( )
inlinestaticprivate

Definition at line 260 of file registry_audit_log.h.

260 {
261 static std::vector<registry_event> events;
262 return events;
263}

Referenced by clear(), event_count(), get_events(), get_events_by_action(), get_events_in_range(), log_event(), and log_event().

Here is the caller graph for this function:

◆ get_mutex()

std::mutex & kcenon::common::interfaces::RegistryAuditLog::get_mutex ( )
inlinestaticprivate

Definition at line 255 of file registry_audit_log.h.

255 {
256 static std::mutex mutex;
257 return mutex;
258}

Referenced by clear(), event_count(), get_events(), get_events_by_action(), get_events_in_range(), log_event(), and log_event().

Here is the caller graph for this function:

◆ is_enabled()

bool kcenon::common::interfaces::RegistryAuditLog::is_enabled ( )
inlinestatic

Check if audit logging is enabled.

Returns
true if audit logging is enabled

Definition at line 325 of file registry_audit_log.h.

325 {
326 return get_enabled_flag().load(std::memory_order_acquire);
327}
static std::atomic< bool > & get_enabled_flag()

References get_enabled_flag().

Referenced by log_event(), and log_event().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ log_event() [1/2]

void kcenon::common::interfaces::RegistryAuditLog::log_event ( const registry_event & event)
inlinestatic

Log a registry event.

Appends the event to the audit log. This operation is thread-safe.

Parameters
eventThe event to log

Definition at line 270 of file registry_audit_log.h.

270 {
271 if (!is_enabled()) {
272 return;
273 }
274
275 std::lock_guard<std::mutex> lock(get_mutex());
276 get_events_internal().push_back(event);
277}
static bool is_enabled()
Check if audit logging is enabled.

References get_events_internal(), get_mutex(), and is_enabled().

Referenced by kcenon::common::di::service_container::check_already_registered(), kcenon::common::di::service_container::check_frozen_for_registration(), kcenon::common::di::service_container::clear(), kcenon::common::interfaces::GlobalLoggerRegistry::clear(), kcenon::common::di::service_container::freeze(), kcenon::common::interfaces::GlobalLoggerRegistry::freeze(), kcenon::common::interfaces::GlobalLoggerRegistry::register_factory(), kcenon::common::di::service_container::register_factory_internal(), kcenon::common::di::service_container::register_instance_internal(), kcenon::common::interfaces::GlobalLoggerRegistry::register_logger(), kcenon::common::interfaces::GlobalLoggerRegistry::set_default_factory(), kcenon::common::interfaces::GlobalLoggerRegistry::set_default_logger(), kcenon::common::di::service_container::unregister_internal(), and kcenon::common::interfaces::GlobalLoggerRegistry::unregister_logger().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ log_event() [2/2]

void kcenon::common::interfaces::RegistryAuditLog::log_event ( registry_event && event)
inlinestatic

Log a registry event (move version).

Parameters
eventThe event to log (moved)

Definition at line 279 of file registry_audit_log.h.

279 {
280 if (!is_enabled()) {
281 return;
282 }
283
284 std::lock_guard<std::mutex> lock(get_mutex());
285 get_events_internal().push_back(std::move(event));
286}

References get_events_internal(), get_mutex(), and is_enabled().

Here is the call graph for this function:

◆ set_enabled()

void kcenon::common::interfaces::RegistryAuditLog::set_enabled ( bool enabled)
inlinestatic

Enable or disable audit logging.

Parameters
enabledWhether to enable audit logging
Note
Disabling audit logging is a security-sensitive operation. Consider logging this action before disabling.

Definition at line 329 of file registry_audit_log.h.

329 {
330 get_enabled_flag().store(enabled, std::memory_order_release);
331}

References get_enabled_flag().

Here is the call graph for this function:

The documentation for this class was generated from the following file: