LogIt++
Header-only, macro-first C++ logging library
Loading...
Searching...
No Matches
ILogReader.hpp
Go to the documentation of this file.
1#pragma once
2#ifndef LOGIT_CPP_HEADER_LOGIT_CPP_LOGIT_LOGGERS_ILOGREADER_HPP_INCLUDED
3#define LOGIT_CPP_HEADER_LOGIT_CPP_LOGIT_LOGGERS_ILOGREADER_HPP_INCLUDED
4
7
8#include "../enums.hpp"
9#include <cstddef>
10#include <cstdint>
11#include <string>
12#include <vector>
13#if __cplusplus >= 201703L
14#include <optional>
15#endif
16
17namespace logit {
18
25 uint64_t session_id = 0;
26 int64_t timestamp_ms = 0;
27 uint32_t sequence = 0;
29 std::string message;
30 uint64_t payload_id = 0;
31 std::string file;
32 std::string function;
33 int line = 0;
34 };
35
38 enum class LogReadOrder {
39 Ascending,
41 };
42
43#if __cplusplus >= 201703L
46 enum class LogReadError {
47 None,
48 NotFound,
49 StorageError,
50 DecodeError,
51 UnsupportedVersion,
52 DecompressionError
53 };
54
57 template <typename T>
58 struct LogReadResult {
59 std::optional<T> value;
60 LogReadError error = LogReadError::None;
61 std::string message;
62 };
63#endif
64
71 class ILogReader {
72 public:
73 virtual ~ILogReader() = default;
74
80 virtual std::vector<LogRecordSnapshot> read_range(
81 int64_t from_ms,
82 int64_t to_ms,
83 std::size_t limit = 0) const = 0;
84
85#if __cplusplus >= 201703L
87 virtual LogReadResult<std::vector<LogRecordSnapshot>> read_range_result(
88 int64_t from_ms,
89 int64_t to_ms,
90 std::size_t limit = 0) const {
91 LogReadResult<std::vector<LogRecordSnapshot>> result;
92 result.value = read_range(from_ms, to_ms, limit);
93 return result;
94 }
95#endif
96
102 virtual std::vector<LogRecordSnapshot> read_recent(
103 std::size_t limit,
104 int64_t period_ms = 0,
105 LogReadOrder order = LogReadOrder::Ascending) const = 0;
106
107#if __cplusplus >= 201703L
109 virtual LogReadResult<std::vector<LogRecordSnapshot>> read_recent_result(
110 std::size_t limit,
111 int64_t period_ms = 0,
113 LogReadResult<std::vector<LogRecordSnapshot>> result;
114 result.value = read_recent(limit, period_ms, order);
115 return result;
116 }
117#endif
118 };
119
120} // namespace logit
121
122#endif // LOGIT_CPP_HEADER_LOGIT_CPP_LOGIT_LOGGERS_ILOGREADER_HPP_INCLUDED
Optional interface for backends that expose stored records.
virtual std::vector< LogRecordSnapshot > read_range(int64_t from_ms, int64_t to_ms, std::size_t limit=0) const =0
Reads records in [from_ms, to_ms) ordered by timestamp.
virtual ~ILogReader()=default
virtual std::vector< LogRecordSnapshot > read_recent(std::size_t limit, int64_t period_ms=0, LogReadOrder order=LogReadOrder::Ascending) const =0
Reads the most recent records.
Enumerations and utility functions for logging levels and text colors.
The primary namespace for the LogIt++ library.
LogLevel
Logging levels.
Definition enums.hpp:15
@ LOG_LVL_TRACE
Trace level logging.
@ None
Store payload bytes as-is.
LogReadOrder
Ordering for query results returned by ILogReader.
@ Ascending
Oldest first.
@ Descending
Newest first.
Common owning snapshot of a stored log record.
std::string message
Formatted message or payload preview.
uint32_t sequence
Per-timestamp sequence, or 0 if unused.
int64_t timestamp_ms
Log timestamp in milliseconds.
int line
Source line number.
uint64_t session_id
Owning session id, or 0 if unused.
uint64_t payload_id
Payload row id, or 0 when absent.
std::string file
Source file path.
std::string function
Source function name.
LogLevel level
Log severity level.