|
template<typename... Args>
requires util::Constructible<EventItems, Args&&...> |
| | LogEvent (int id, Args &&... args) |
| | Template constructor with perfect forwarding.
|
| |
| | LogEvent (int id, std::initializer_list< std::pair< std::string, std::string > > items) |
| | Constructs a LogEvent from an initializer list.
|
| |
| int | getId () const |
| | Gets the unique ID of the event.
|
| |
| const EventItems & | getEventItems () const |
| | Gets a const reference to the event's data items.
|
| |
| const std::string | findByKey (std::string_view key) const |
| | Finds a value by its key in the event's items.
|
| |
| const std::vector< std::string > | findAllByKey (std::string_view key) const |
| | Finds all values by its key in the event's items.
|
| |
| EventItemsIterator | findInEvent (const std::string &search) |
| | Finds an iterator to the first item matching the search term.
|
| |
| bool | operator== (const LogEvent &other) const |
| | Equality comparison operator.
|
| |
| void | SetOriginalId (int originalId) |
| | Sets the original ID before merge (stores as event data)
|
| |
| void | SetId (int newId) |
| | Updates the event's ID (used during merge to reassign sequential IDs)
|
| |
| const std::string & | GetSource () const |
| | Gets the source identifier for this event.
|
| |
| void | SetSource (const std::string &source) |
| | Sets the source identifier for this event.
|
| |
Represents a single, structured log event with key-value data.
A LogEvent encapsulates a log entry as a collection of key-value pairs, providing efficient access to structured log data. Each event has a unique identifier and contains metadata such as timestamps, severity levels, and custom attributes.
- Design Philosophy
- LogEvent is optimized for:
- Memory efficiency through move semantics and perfect forwarding
- Integration with filtering and display systems
- Support for multi-source event merging with original ID tracking
- Key Features
- Key-value lookup: O(n) linear scan over a typically small field list — deliberately not a per-event hash index (see findByKey())
- Multiple source tracking: Identifies events from different log files
- Original ID preservation: Retains pre-merge IDs for traceability
- Flexible construction: Supports initializer lists and perfect forwarding
- Thread Safety
- This class is not thread-safe. External synchronization is required when accessing LogEvent instances from multiple threads. For thread-safe collection management, use EventsContainer instead.
- Memory Management
- LogEvent uses move semantics and perfect forwarding where possible to minimize unnecessary copying of large data sets. Events are typically moved into EventsContainer for storage.
- Usage Examples
Creating events from initializer list:
{"timestamp", "2025-03-15T12:00:00Z"},
{"level", "ERROR"},
{"message", "Database connection failed"},
{"source", "db_engine"}
});
std::string timestamp =
event.
findByKey(
"timestamp");
std::cout << "Level: " << event.findByKey("level") << std::endl;
Represents a single, structured log event with key-value data.
Definition LogEvent.hpp:97
const std::string findByKey(std::string_view key) const
Finds a value by its key in the event's items.
Definition LogEvent.cpp:25
Searching for values:
if (!event.findByKey("error_code").empty()) {
std::cout << "Error code: " << event.findByKey("error_code") << std::endl;
}
Iterating through event data:
std::cout << key << " = " << value << std::endl;
}
const EventItems & getEventItems() const
Gets a const reference to the event's data items.
Definition LogEvent.cpp:20
Working with merged events:
original_event.SetId(100);
original_event.SetSource("log_file_1.txt");
void SetOriginalId(int originalId)
Sets the original ID before merge (stores as event data)
Definition LogEvent.cpp:72
- See also
- EventsContainer for thread-safe collection management
-
FilterManager for filtering events based on key-value data