11#include "errors/fatal.h"
12#include "threads/thread.h"
20 _queue(capacity, initial),
21 _on_thread_initialize(on_thread_initialize),
22 _on_thread_clenup(on_thread_clenup)
48 _thread = CppCommon::Thread::Start([
this]() { ProcessThread(_on_thread_initialize, _on_thread_clenup); });
79 return EnqueueRecord(record);
82bool AsyncWaitProcessor::EnqueueRecord(
Record& record)
85 return _queue.Enqueue(record);
88void AsyncWaitProcessor::ProcessThread(
const std::function<
void ()>& on_thread_initialize,
const std::function<
void ()>& on_thread_clenup)
91 assert((on_thread_initialize) &&
"Thread initialize handler must be valid!");
92 if (on_thread_initialize)
93 on_thread_initialize();
98 thread_local std::vector<Record> records;
99 thread_local uint64_t previous = 0;
102 records.reserve(_queue.capacity());
107 if (!_queue.Dequeue(records))
111 uint64_t current = 0;
114 for (
auto& record : records)
137 if (CppCommon::Timespan((int64_t)(current - previous)).seconds() > 1)
147 catch (
const std::exception& ex)
153 fatality(
"Asynchronous wait logging processor terminated!");
157 assert((on_thread_clenup) &&
"Thread cleanup handler must be valid!");
158 if (on_thread_clenup)
169 thread_local Record flush;
173 EnqueueRecord(flush);
Asynchronous wait logging processor definition.
AsyncWaitProcessor(const std::shared_ptr< Layout > &layout, bool auto_start=true, size_t capacity=8192, size_t initial=8192, const std::function< void()> &on_thread_initialize=[](){}, const std::function< void()> &on_thread_clenup=[](){})
Initialize asynchronous processor with a given layout interface.
bool ProcessRecord(Record &record) override
Process the given logging record through all child filters, layouts and appenders.
virtual ~AsyncWaitProcessor()
bool Start() override
Start the logging element.
void Flush() override
Flush the current logging processor.
bool Stop() override
Stop the logging element.
Processor(const std::shared_ptr< Layout > &layout)
Initialize logging processor with a given layout interface.
std::shared_ptr< Layout > & layout() noexcept
Get the logging processor layout.
bool IsStarted() const noexcept override
Is the logging processor started?
bool Stop() override
Stop the logging processor.
virtual bool ProcessRecord(Record &record)
Process the given logging record through all child filters, layouts and appenders.
bool Start() override
Start the logging processor.
std::atomic< bool > _started
virtual void Flush()
Flush the current logging processor.
uint64_t timestamp
Timestamp of the logging record.
C++ Logging project definitions.