mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-06-01 01:54:00 +00:00
fixes
This commit is contained in:
@@ -51,6 +51,12 @@ class BiergartenPipelineOrchestrator {
|
||||
* 2. Resolve context for each city using the injected context service
|
||||
* 3. Generate brewery data for sampled cities
|
||||
*
|
||||
* @note STRUCTURAL CONCURRENCY REQUIREMENT:
|
||||
* When transitioned to a multithreaded design, this method MUST structurally
|
||||
* enforce that all deployed worker threads are joined before returning (e.g.
|
||||
* by using std::jthread or a structured concurrency primitive). This ensures
|
||||
* workers do not attempt to log to a closed channel during application teardown.
|
||||
*
|
||||
* @return true if successful, false if not
|
||||
*/
|
||||
bool Run();
|
||||
|
||||
@@ -43,23 +43,35 @@ enum class PipelinePhase {
|
||||
Teardown, ///< Finalization and cleanup.
|
||||
};
|
||||
|
||||
/**
|
||||
* @struct LogDTO
|
||||
* @brief User-provided subset of log fields. Used to capture call-site info transparently.
|
||||
*/
|
||||
struct LogDTO {
|
||||
LogLevel level;
|
||||
PipelinePhase phase;
|
||||
std::string message;
|
||||
};
|
||||
|
||||
/**
|
||||
* @struct LogEntry
|
||||
* @brief Single structured log event.
|
||||
*
|
||||
* All fields are value types, which keeps transfer across the bounded channel
|
||||
* simple and avoids shared ownership.
|
||||
*
|
||||
* NOTE: timestamp, thread_id, and origin must be populated by ILogger::Log()
|
||||
* before the entry is dispatched.
|
||||
*/
|
||||
struct LogEntry {
|
||||
/// @brief Timestamp when the entry was created.
|
||||
std::chrono::system_clock::time_point timestamp =
|
||||
std::chrono::system_clock::now();
|
||||
std::chrono::system_clock::time_point timestamp{};
|
||||
|
||||
/// @brief Source location where the log call was made.
|
||||
std::source_location origin = std::source_location::current();
|
||||
std::source_location origin{};
|
||||
|
||||
/// @brief Thread responsible for emitting the log.
|
||||
std::thread::id thread_id = std::this_thread::get_id();
|
||||
std::thread::id thread_id{};
|
||||
|
||||
|
||||
/// @brief Severity level of this entry.
|
||||
|
||||
@@ -24,29 +24,30 @@
|
||||
*/
|
||||
class LogProducer final : public ILogger {
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a channel-backed producer.
|
||||
*
|
||||
* @param channel Reference to the bounded channel used for log transfer.
|
||||
*/
|
||||
explicit LogProducer(BoundedChannel<LogEntry>& channel);
|
||||
/**
|
||||
* @brief Construct a channel-backed producer.
|
||||
*
|
||||
* @param channel Reference to the bounded channel used for log transfer.
|
||||
*/
|
||||
explicit LogProducer(BoundedChannel<LogEntry>& channel);
|
||||
|
||||
LogProducer(const LogProducer&) = delete;
|
||||
LogProducer& operator=(const LogProducer&) = delete;
|
||||
LogProducer(LogProducer&&) = delete;
|
||||
LogProducer& operator=(LogProducer&&) = delete;
|
||||
LogProducer(const LogProducer&) = delete;
|
||||
LogProducer& operator=(const LogProducer&) = delete;
|
||||
LogProducer(LogProducer&&) = delete;
|
||||
LogProducer& operator=(LogProducer&&) = delete;
|
||||
|
||||
~LogProducer() override = default;
|
||||
~LogProducer() override = default;
|
||||
|
||||
/**
|
||||
* @brief Queue a log message for asynchronous processing.
|
||||
*
|
||||
* Blocks while the channel applies backpressure.
|
||||
*/
|
||||
void Log(LogEntry log_entry) override;
|
||||
/**
|
||||
* @brief Queue a log message for asynchronous processing.
|
||||
*
|
||||
* Blocks while the channel applies backpressure. This blocking behavior
|
||||
* under heavy load is an accepted trade-off for simplicity.
|
||||
*/
|
||||
void DoLog(LogEntry log_entry) override;
|
||||
|
||||
private:
|
||||
BoundedChannel<LogEntry>& channel_;
|
||||
BoundedChannel<LogEntry>& channel_;
|
||||
};
|
||||
|
||||
#endif // BIERGARTEN_PIPELINE_INCLUDES_SERVICES_LOGGING_CHANNEL_LOGGER_H_
|
||||
|
||||
@@ -34,9 +34,31 @@ class ILogger {
|
||||
/**
|
||||
* @brief Submit a log message to the logging subsystem.
|
||||
*
|
||||
* @param log_entry Structured log entry data.
|
||||
* @param payload User-provided log data (level, phase, message).
|
||||
* @param origin Auto-captured source location of the call site.
|
||||
*/
|
||||
virtual void Log(LogEntry log_entry) = 0;
|
||||
void Log(LogDTO payload,
|
||||
std::source_location origin = std::source_location::current(),
|
||||
std::chrono::system_clock::time_point timestamp = std::chrono::system_clock::now(),
|
||||
std::thread::id thread_id = std::this_thread::get_id()) {
|
||||
LogEntry entry;
|
||||
entry.timestamp = timestamp;
|
||||
entry.thread_id = thread_id;
|
||||
entry.level = payload.level;
|
||||
entry.phase = payload.phase;
|
||||
entry.message = std::move(payload.message);
|
||||
entry.origin = origin;
|
||||
DoLog(std::move(entry));
|
||||
}
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief Underlying implementation to transport the log entry.
|
||||
*
|
||||
* Implementations must be thread-safe as DoLog can be called concurrently
|
||||
* from multiple worker threads.
|
||||
*/
|
||||
virtual void DoLog(LogEntry log_entry) = 0;
|
||||
};
|
||||
|
||||
#endif // BIERGARTEN_PIPELINE_INCLUDES_SERVICES_LOGGING_LOGGER_H_
|
||||
|
||||
Reference in New Issue
Block a user