74 default:
return "unknown";
123 bool succeeded =
true,
124 std::string
error =
"")
127 ,
file(loc.file_name())
128 ,
line(static_cast<int>(loc.
line()))
130 ,
timestamp(std::chrono::system_clock::now())
187 static std::vector<registry_event>
get_events();
205 std::chrono::system_clock::time_point start,
206 std::chrono::system_clock::time_point end);
256 static std::mutex mutex;
261 static std::vector<registry_event> events;
266 static std::atomic<bool> enabled{
true};
275 std::lock_guard<std::mutex> lock(
get_mutex());
284 std::lock_guard<std::mutex> lock(
get_mutex());
289 std::lock_guard<std::mutex> lock(
get_mutex());
295 std::lock_guard<std::mutex> lock(
get_mutex());
297 std::vector<registry_event> result;
299 if (
event.action == action) {
300 result.push_back(
event);
307 std::chrono::system_clock::time_point start,
308 std::chrono::system_clock::time_point end) {
309 std::lock_guard<std::mutex> lock(
get_mutex());
311 std::vector<registry_event> result;
313 if (
event.timestamp >= start &&
event.timestamp <= end) {
314 result.push_back(
event);
321 std::lock_guard<std::mutex> lock(
get_mutex());
334 std::lock_guard<std::mutex> lock(
get_mutex());
Thread-safe audit log for registry operations.
static std::vector< registry_event > get_events_in_range(std::chrono::system_clock::time_point start, std::chrono::system_clock::time_point end)
Get events within a time range.
static std::vector< registry_event > get_events_by_action(registry_action action)
Get events filtered by action type.
static std::vector< registry_event > get_events()
Get all logged events.
static void log_event(const registry_event &event)
Log a registry event.
static void clear()
Clear all audit events.
static void set_enabled(bool enabled)
Enable or disable audit logging.
static size_t event_count()
Get the number of logged events.
static bool is_enabled()
Check if audit logging is enabled.
RegistryAuditLog()=delete
static std::vector< registry_event > & get_events_internal()
static std::atomic< bool > & get_enabled_flag()
static std::mutex & get_mutex()
registry_action
Types of registry mutation actions.
@ set_default_logger
Default logger set.
@ register_service
Service registration.
@ freeze_logger_registry
Freeze logger registry.
@ unregister_service
Service unregistration.
@ clear_loggers
Clear all loggers.
@ register_logger
Logger registration.
@ freeze_service_container
Freeze service container.
@ set_default_factory
Default factory set (logger)
@ clear_services
Clear all services.
@ unregister_logger
Logger unregistration.
@ register_factory
Factory registration (logger)
std::string to_string(log_level level)
Convert log level to string.
C++17-compatible source_location implementation.
Generic event structure for the event bus.
Represents a single audit event for registry mutations.
int line
Line number where the operation was initiated.
std::chrono::system_clock::time_point timestamp
Timestamp when the event occurred.
registry_event(registry_action act, std::string target, const source_location &loc=source_location::current(), bool succeeded=true, std::string error="")
Construct a registry event.
bool success
Whether the operation was successful.
std::string function
Function where the operation was initiated.
std::string file
File where the operation was initiated.
std::string target_name
Name of the service or logger (empty for clear/freeze operations)
registry_action action
The type of action performed.
std::string error_message
Error message if the operation failed (empty on success)
C++17-compatible source_location implementation using compiler builtins.
static constexpr source_location current(const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE()) noexcept