Files
the-biergarten-app/tooling/pipeline/includes/services/logging/log_consumer.h

45 lines
1.3 KiB
C++

/**
* @file services/logging/log_consumer.h
* @brief Dedicated log drain worker for the pipeline logging channel.
*
* LogConsumer runs on its own thread, draining LogEntry items from a
* BoundedChannel<LogEntry> and forwarding them to spdlog. Exits cleanly
* when the channel is closed.
*/
#ifndef BIERGARTEN_PIPELINE_INCLUDES_SERVICES_LOGGING_LOG_CONSUMER_H_
#define BIERGARTEN_PIPELINE_INCLUDES_SERVICES_LOGGING_LOG_CONSUMER_H_
#include <spdlog/spdlog.h>
#include <string>
#include "concurrency/bounded_channel.h"
#include "services/logging/log_entry.h"
class LogConsumer {
public:
explicit LogConsumer(BoundedChannel<LogEntry>& channel);
LogConsumer(const LogConsumer&) = delete;
LogConsumer& operator=(const LogConsumer&) = delete;
LogConsumer(LogConsumer&&) = delete;
LogConsumer& operator=(LogConsumer&&) = delete;
/**
* @brief Drains the channel until it is closed.
*
* Intended to be run on a dedicated std::thread. Exits when:
* - The channel is closed and the queue is fully drained.
*/
void Run();
private:
BoundedChannel<LogEntry>& channel_;
static spdlog::level::level_enum ToSpdlogLevel(LogLevel level);
static std::string ToString(PipelinePhase phase);
};
#endif // BIERGARTEN_PIPELINE_INCLUDES_SERVICES_LOGGING_LOG_CONSUMER_H_