mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-10-15 01:54:43 +00:00
Formatted includes/services/logging
This commit is contained in:
@@ -22,32 +22,32 @@
|
|||||||
* and exit once the channel has been closed and drained.
|
* and exit once the channel has been closed and drained.
|
||||||
*/
|
*/
|
||||||
class LogDispatcher {
|
class LogDispatcher {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Construct a log dispatcher.
|
* @brief Construct a log dispatcher.
|
||||||
*
|
*
|
||||||
* @param channel Reference to the bounded channel used for log retrieval.
|
* @param channel Reference to the bounded channel used for log retrieval.
|
||||||
*/
|
*/
|
||||||
explicit LogDispatcher(BoundedChannel<LogEntry>& channel);
|
explicit LogDispatcher(BoundedChannel<LogEntry>& channel);
|
||||||
|
|
||||||
LogDispatcher(const LogDispatcher&) = delete;
|
LogDispatcher(const LogDispatcher&) = delete;
|
||||||
LogDispatcher& operator=(const LogDispatcher&) = delete;
|
LogDispatcher& operator=(const LogDispatcher&) = delete;
|
||||||
LogDispatcher(LogDispatcher&&) = delete;
|
LogDispatcher(LogDispatcher&&) = delete;
|
||||||
LogDispatcher& operator=(LogDispatcher&&) = delete;
|
LogDispatcher& operator=(LogDispatcher&&) = delete;
|
||||||
~LogDispatcher() = default;
|
~LogDispatcher() = default;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Drain the channel and forward entries to spdlog.
|
* @brief Drain the channel and forward entries to spdlog.
|
||||||
*
|
*
|
||||||
* Intended to be called once on a dedicated thread. The loop returns after
|
* Intended to be called once on a dedicated thread. The loop returns after
|
||||||
* the channel has been closed and all queued entries have been processed.
|
* the channel has been closed and all queued entries have been processed.
|
||||||
*/
|
*/
|
||||||
void Run();
|
void Run();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BoundedChannel<LogEntry>& channel_;
|
BoundedChannel<LogEntry>& channel_;
|
||||||
|
|
||||||
static spdlog::level::level_enum ToSpdlogLevel(LogLevel level);
|
static spdlog::level::level_enum ToSpdlogLevel(LogLevel level);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BIERGARTEN_PIPELINE_INCLUDES_SERVICES_LOGGING_LOG_DISPATCHER_H_
|
#endif // BIERGARTEN_PIPELINE_INCLUDES_SERVICES_LOGGING_LOG_DISPATCHER_H_
|
||||||
|
|||||||
@@ -20,22 +20,22 @@
|
|||||||
* @brief Severity levels supported by the logging infra.
|
* @brief Severity levels supported by the logging infra.
|
||||||
*/
|
*/
|
||||||
enum class LogLevel {
|
enum class LogLevel {
|
||||||
/**
|
/**
|
||||||
* @brief Development/debugging information.
|
* @brief Development/debugging information.
|
||||||
*/
|
*/
|
||||||
Debug,
|
Debug,
|
||||||
/**
|
/**
|
||||||
* @brief General informational messages.
|
* @brief General informational messages.
|
||||||
*/
|
*/
|
||||||
Info,
|
Info,
|
||||||
/**
|
/**
|
||||||
* @brief Warning conditions.
|
* @brief Warning conditions.
|
||||||
*/
|
*/
|
||||||
Warn,
|
Warn,
|
||||||
/**
|
/**
|
||||||
* @brief Error conditions.
|
* @brief Error conditions.
|
||||||
*/
|
*/
|
||||||
Error,
|
Error,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -46,38 +46,38 @@ enum class LogLevel {
|
|||||||
* pipeline that emitted it.
|
* pipeline that emitted it.
|
||||||
*/
|
*/
|
||||||
enum class PipelinePhase {
|
enum class PipelinePhase {
|
||||||
/**
|
/**
|
||||||
* @brief Initialization and validation.
|
* @brief Initialization and validation.
|
||||||
*/
|
*/
|
||||||
Startup,
|
Startup,
|
||||||
/**
|
/**
|
||||||
* @brief City/context enrichment (e.g. Wikipedia lookups).
|
* @brief City/context enrichment (e.g. Wikipedia lookups).
|
||||||
*/
|
*/
|
||||||
Enrichment,
|
Enrichment,
|
||||||
/**
|
/**
|
||||||
* @brief User profile generation.
|
* @brief User profile generation.
|
||||||
*/
|
*/
|
||||||
UserGeneration,
|
UserGeneration,
|
||||||
/**
|
/**
|
||||||
* @brief Brewery and beer data generation.
|
* @brief Brewery and beer data generation.
|
||||||
*/
|
*/
|
||||||
BreweryAndBeerGeneration,
|
BreweryAndBeerGeneration,
|
||||||
/**
|
/**
|
||||||
* @brief Checkin (visit) record generation.
|
* @brief Checkin (visit) record generation.
|
||||||
*/
|
*/
|
||||||
CheckinGeneration,
|
CheckinGeneration,
|
||||||
/**
|
/**
|
||||||
* @brief Rating and review generation.
|
* @brief Rating and review generation.
|
||||||
*/
|
*/
|
||||||
RatingGeneration,
|
RatingGeneration,
|
||||||
/**
|
/**
|
||||||
* @brief Follow relationship generation.
|
* @brief Follow relationship generation.
|
||||||
*/
|
*/
|
||||||
FollowGeneration,
|
FollowGeneration,
|
||||||
/**
|
/**
|
||||||
* @brief Finalization and cleanup.
|
* @brief Finalization and cleanup.
|
||||||
*/
|
*/
|
||||||
Teardown,
|
Teardown,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -86,9 +86,9 @@ enum class PipelinePhase {
|
|||||||
* transparently.
|
* transparently.
|
||||||
*/
|
*/
|
||||||
struct LogDTO {
|
struct LogDTO {
|
||||||
LogLevel level;
|
LogLevel level;
|
||||||
PipelinePhase phase;
|
PipelinePhase phase;
|
||||||
std::string message;
|
std::string message;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -102,35 +102,35 @@ struct LogDTO {
|
|||||||
* before the entry is dispatched.
|
* before the entry is dispatched.
|
||||||
*/
|
*/
|
||||||
struct LogEntry {
|
struct LogEntry {
|
||||||
/**
|
/**
|
||||||
* @brief Timestamp when the entry was created.
|
* @brief Timestamp when the entry was created.
|
||||||
*/
|
*/
|
||||||
std::chrono::system_clock::time_point timestamp{};
|
std::chrono::system_clock::time_point timestamp{};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Source location where the log call was made.
|
* @brief Source location where the log call was made.
|
||||||
*/
|
*/
|
||||||
std::source_location origin{};
|
std::source_location origin{};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Thread responsible for emitting the log.
|
* @brief Thread responsible for emitting the log.
|
||||||
*/
|
*/
|
||||||
std::thread::id thread_id{};
|
std::thread::id thread_id{};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Severity level of this entry.
|
* @brief Severity level of this entry.
|
||||||
*/
|
*/
|
||||||
LogLevel level;
|
LogLevel level;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Pipeline phase associated with the entry.
|
* @brief Pipeline phase associated with the entry.
|
||||||
*/
|
*/
|
||||||
PipelinePhase phase;
|
PipelinePhase phase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Log message text.
|
* @brief Log message text.
|
||||||
*/
|
*/
|
||||||
std::string message;
|
std::string message;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BIERGARTEN_PIPELINE_INCLUDES_SERVICES_LOGGING_LOG_ENTRY_H_
|
#endif // BIERGARTEN_PIPELINE_INCLUDES_SERVICES_LOGGING_LOG_ENTRY_H_
|
||||||
|
|||||||
@@ -23,31 +23,31 @@
|
|||||||
* remain valid for the lifetime of the producer.
|
* remain valid for the lifetime of the producer.
|
||||||
*/
|
*/
|
||||||
class LogProducer final : public ILogger {
|
class LogProducer final : public ILogger {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Construct a channel-backed producer.
|
* @brief Construct a channel-backed producer.
|
||||||
*
|
*
|
||||||
* @param channel Reference to the bounded channel used for log transfer.
|
* @param channel Reference to the bounded channel used for log transfer.
|
||||||
*/
|
*/
|
||||||
explicit LogProducer(BoundedChannel<LogEntry>& channel);
|
explicit LogProducer(BoundedChannel<LogEntry>& channel);
|
||||||
|
|
||||||
LogProducer(const LogProducer&) = delete;
|
LogProducer(const LogProducer&) = delete;
|
||||||
LogProducer& operator=(const LogProducer&) = delete;
|
LogProducer& operator=(const LogProducer&) = delete;
|
||||||
LogProducer(LogProducer&&) = delete;
|
LogProducer(LogProducer&&) = delete;
|
||||||
LogProducer& operator=(LogProducer&&) = delete;
|
LogProducer& operator=(LogProducer&&) = delete;
|
||||||
|
|
||||||
~LogProducer() override = default;
|
~LogProducer() override = default;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Queue a log message for asynchronous processing.
|
* @brief Queue a log message for asynchronous processing.
|
||||||
*
|
*
|
||||||
* Blocks while the channel applies backpressure. This blocking behavior
|
* Blocks while the channel applies backpressure. This blocking behavior
|
||||||
* under heavy load is an accepted trade-off for simplicity.
|
* under heavy load is an accepted trade-off for simplicity.
|
||||||
*/
|
*/
|
||||||
void DoLog(LogEntry log_entry) override;
|
void DoLog(LogEntry log_entry) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BoundedChannel<LogEntry>& channel_;
|
BoundedChannel<LogEntry>& channel_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BIERGARTEN_PIPELINE_INCLUDES_SERVICES_LOGGING_LOG_PRODUCER_H_
|
#endif // BIERGARTEN_PIPELINE_INCLUDES_SERVICES_LOGGING_LOG_PRODUCER_H_
|
||||||
|
|||||||
@@ -23,43 +23,43 @@
|
|||||||
* by the composition root and injected into services that emit diagnostics.
|
* by the composition root and injected into services that emit diagnostics.
|
||||||
*/
|
*/
|
||||||
class ILogger {
|
class ILogger {
|
||||||
public:
|
public:
|
||||||
ILogger() = default;
|
ILogger() = default;
|
||||||
ILogger(const ILogger&) = delete;
|
ILogger(const ILogger&) = delete;
|
||||||
ILogger& operator=(const ILogger&) = delete;
|
ILogger& operator=(const ILogger&) = delete;
|
||||||
ILogger(ILogger&&) = delete;
|
ILogger(ILogger&&) = delete;
|
||||||
ILogger& operator=(ILogger&&) = delete;
|
ILogger& operator=(ILogger&&) = delete;
|
||||||
virtual ~ILogger() = default;
|
virtual ~ILogger() = default;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Submit a log message to the logging subsystem.
|
* @brief Submit a log message to the logging subsystem.
|
||||||
*
|
*
|
||||||
* @param payload User-provided log data (level, phase, message).
|
* @param payload User-provided log data (level, phase, message).
|
||||||
* @param origin Auto-captured source location of the call site.
|
* @param origin Auto-captured source location of the call site.
|
||||||
*/
|
*/
|
||||||
void Log(LogDTO payload,
|
void Log(LogDTO payload,
|
||||||
std::source_location origin = std::source_location::current(),
|
std::source_location origin = std::source_location::current(),
|
||||||
std::chrono::system_clock::time_point timestamp =
|
std::chrono::system_clock::time_point timestamp =
|
||||||
std::chrono::system_clock::now(),
|
std::chrono::system_clock::now(),
|
||||||
std::thread::id thread_id = std::this_thread::get_id()) {
|
std::thread::id thread_id = std::this_thread::get_id()) {
|
||||||
LogEntry entry;
|
LogEntry entry;
|
||||||
entry.timestamp = timestamp;
|
entry.timestamp = timestamp;
|
||||||
entry.thread_id = thread_id;
|
entry.thread_id = thread_id;
|
||||||
entry.level = payload.level;
|
entry.level = payload.level;
|
||||||
entry.phase = payload.phase;
|
entry.phase = payload.phase;
|
||||||
entry.message = std::move(payload.message);
|
entry.message = std::move(payload.message);
|
||||||
entry.origin = origin;
|
entry.origin = origin;
|
||||||
DoLog(std::move(entry));
|
DoLog(std::move(entry));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* @brief Underlying implementation to transport the log entry.
|
* @brief Underlying implementation to transport the log entry.
|
||||||
*
|
*
|
||||||
* Implementations must be thread-safe as DoLog can be called concurrently
|
* Implementations must be thread-safe as DoLog can be called concurrently
|
||||||
* from multiple worker threads.
|
* from multiple worker threads.
|
||||||
*/
|
*/
|
||||||
virtual void DoLog(LogEntry log_entry) = 0;
|
virtual void DoLog(LogEntry log_entry) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BIERGARTEN_PIPELINE_INCLUDES_SERVICES_LOGGING_LOGGER_H_
|
#endif // BIERGARTEN_PIPELINE_INCLUDES_SERVICES_LOGGING_LOGGER_H_
|
||||||
|
|||||||
Reference in New Issue
Block a user