LogIt++
Header-only, macro-first C++ logging library
Loading...
Searching...
No Matches
ILogger.hpp
Go to the documentation of this file.
1#pragma once
2#ifndef LOGIT_CPP_HEADER_LOGIT_CPP_LOGIT_LOGGERS_ILOGGER_HPP_INCLUDED
3#define LOGIT_CPP_HEADER_LOGIT_CPP_LOGIT_LOGGERS_ILOGGER_HPP_INCLUDED
4
7
10
11#include <cstddef>
12#include <string>
13#include <vector>
14
15namespace logit {
16
21 bool include_payloads = true;
22 bool include_sessions = false;
23 };
24
27 enum class LogClearStatus {
28 Cleared,
30 Failed
31 };
32
36 bool ok = false;
38 std::size_t cleared_records = 0;
39 std::string message;
40 };
41
44
47 class ILogger {
48 public:
49 virtual ~ILogger() = default;
50
58 virtual void log(const LogRecord& record, const std::string& message) = 0;
59
64 virtual std::string get_string_param(const LoggerParam& param) const = 0;
65
70 virtual int64_t get_int_param(const LoggerParam& param) const = 0;
71
76 virtual double get_float_param(const LoggerParam& param) const = 0;
77
80 virtual void set_log_level(LogLevel level) = 0;
81
84 virtual LogLevel get_log_level() const = 0;
85
90 virtual std::vector<std::string> get_buffered_strings() const {
91 return std::vector<std::string>();
92 }
93
98 virtual std::vector<BufferedLogEntry> get_buffered_entries() const {
99 return std::vector<BufferedLogEntry>();
100 }
101
107 virtual std::vector<LogFileInfo> list_log_files() const {
108 return std::vector<LogFileInfo>();
109 }
110
116 virtual LogFileReadResult read_log_file(const std::string& path) const {
117 LogFileReadResult result;
118 result.file.path = path;
119 result.ok = false;
120 return result;
121 }
122
128 virtual std::vector<LogFileReadResult> read_log_files(const std::vector<std::string>& paths) const {
129 std::vector<LogFileReadResult> results;
130 results.reserve(paths.size());
131 for (size_t i = 0; i < paths.size(); ++i) {
132 results.push_back(read_log_file(paths[i]));
133 }
134 return results;
135 }
136
141 (void)options;
142 LogClearResult result;
143 result.ok = false;
145 result.message = "unsupported";
146 return result;
147 }
148
153 virtual void wait() = 0;
154
159 virtual void shutdown() {
160 wait();
161 }
162 }; // ILogger
163
164}; // namespace logit
165
167
168#endif // LOGIT_CPP_HEADER_LOGIT_CPP_LOGIT_LOGGERS_ILOGGER_HPP_INCLUDED
Optional buffered snapshot access returns empty results by default.
Definition ILogger.hpp:47
virtual double get_float_param(const LoggerParam &param) const =0
Retrieves a floating-point parameter from the logger.
virtual void set_log_level(LogLevel level)=0
Sets the minimal log level for this logger.
virtual int64_t get_int_param(const LoggerParam &param) const =0
Retrieves an integer parameter from the logger.
virtual void log(const LogRecord &record, const std::string &message)=0
Logs a message.
virtual std::string get_string_param(const LoggerParam &param) const =0
Retrieves a string parameter from the logger.
virtual void wait()=0
Waits for all asynchronous logging operations to complete.
virtual ~ILogger()=default
virtual void shutdown()
Stops logger-owned asynchronous resources after draining pending work.
Definition ILogger.hpp:159
virtual std::vector< LogFileReadResult > read_log_files(const std::vector< std::string > &paths) const
Reads several persisted log files owned by this backend.
Definition ILogger.hpp:128
virtual std::vector< std::string > get_buffered_strings() const
Returns buffered formatted messages in chronological order.
Definition ILogger.hpp:90
virtual LogClearResult clear_logs(const LogClearOptions &options=LogClearOptions())
Clears logger-owned buffered or persisted records when supported.
Definition ILogger.hpp:140
virtual std::vector< BufferedLogEntry > get_buffered_entries() const
Returns buffered structured entries in chronological order.
Definition ILogger.hpp:98
virtual std::vector< LogFileInfo > list_log_files() const
Lists persisted log files owned by this backend.
Definition ILogger.hpp:107
virtual LogLevel get_log_level() const =0
Gets the minimal log level for this logger.
virtual LogFileReadResult read_log_file(const std::string &path) const
Reads one persisted log file owned by this backend.
Definition ILogger.hpp:116
The primary namespace for the LogIt++ library.
LogLevel
Logging levels.
Definition enums.hpp:15
LoggerParam
Enumeration for different logger parameters that can be retrieved.
Definition enums.hpp:47
LogClearStatus
Backend cleanup status.
Definition ILogger.hpp:27
Selects which data categories a logger cleanup should remove.
Definition ILogger.hpp:19
bool include_persistent_records
Clear primary stored log records.
Definition ILogger.hpp:20
bool include_payloads
Clear associated payload/blob data.
Definition ILogger.hpp:21
bool include_sessions
Clear session metadata when supported.
Definition ILogger.hpp:22
Result returned by logger cleanup operations.
Definition ILogger.hpp:35
std::string message
Optional diagnostic or unsupported reason.
Definition ILogger.hpp:39
std::size_t cleared_records
Number of primary records/files cleared when available.
Definition ILogger.hpp:38
LogClearStatus status
Detailed cleanup status.
Definition ILogger.hpp:37
bool ok
True when the backend completed cleanup.
Definition ILogger.hpp:36
std::string path
Full path to the file.
Result of reading a persisted log file from a file-based backend.
LogFileInfo file
Metadata for the requested file.
bool ok
Whether the read succeeded.
Stores log metadata and content.
Definition LogRecord.hpp:17