Corium 1.1.0
High-Performance Zero-Heap C++20 MPSC Application Runtime
Loading...
Searching...
No Matches
LogBackgroundService.hpp
Go to the documentation of this file.
1
7#pragma once
8
9#include <chrono>
10#include <stop_token>
11#include <thread>
12#include <utility>
13
16
17namespace corium::logging {
18
24template <typename LogSink = sinks::ConsoleLogSink, typename EventVariant = DefaultEvents, std::size_t MaxMessageSize = 256>
25class LogBackgroundService : public BackgroundService<EventVariant> {
26public:
28
29 explicit LogBackgroundService(const char* category = "LogService", LogLevel minLevel = LogLevel::Info, LogSink sink = LogSink{})
30 : _logger(category, minLevel, std::move(sink))
31 {}
32
34 [[nodiscard]] LoggerType& logger() noexcept { return _logger; }
35 [[nodiscard]] const LoggerType& logger() const noexcept { return _logger; }
36
38 template <typename... Args>
39 void info(const char* fmt, Args&&... args) const
40 {
41 _logger.info(fmt, std::forward<Args>(args)...);
42 }
43
45 void run(const std::stop_token& stopToken)
46 {
47 _logger.info("Asynchronous LogBackgroundService started.");
48 while (!stopToken.stop_requested()) {
49 std::this_thread::sleep_for(std::chrono::milliseconds(100));
50 }
51 _logger.info("Asynchronous LogBackgroundService stopping.");
52 }
53
54private:
55 LoggerType _logger;
56};
57
58} // namespace corium::logging
Managed worker thread using C++20 std::jthread and std::stop_token.
Static logger frontend with compile-time formatting and severity filtering.
Multi-threaded background worker service owning a dedicated std::jthread. Integrates incoming event q...
Definition BackgroundService.hpp:35
EventSinkT< EventVariant > sink() noexcept
Get an EventSink handle targeting this service's incoming event queue.
Definition Service.hpp:62
Asynchronous background logging service executing on a dedicated C++20 std::jthread....
Definition LogBackgroundService.hpp:25
void info(const char *fmt, Args &&... args) const
Log background heartbeat or event message.
Definition LogBackgroundService.hpp:39
LogBackgroundService(const char *category="LogService", LogLevel minLevel=LogLevel::Info, LogSink sink=LogSink{})
Definition LogBackgroundService.hpp:29
void run(const std::stop_token &stopToken)
Main background execution loop.
Definition LogBackgroundService.hpp:45
LoggerT< LogSink, MaxMessageSize > LoggerType
Definition LogBackgroundService.hpp:27
const LoggerType & logger() const noexcept
Definition LogBackgroundService.hpp:35
LoggerType & logger() noexcept
Access embedded logger instance.
Definition LogBackgroundService.hpp:34
Static compile-time logger wrapper managing severity level filtering and zero-heap string formatting.
Definition Logger.hpp:24
void info(const char *fmt, Args &&... args) const
Definition Logger.hpp:115
Definition LogBackgroundService.hpp:17
LogLevel
Logging severity levels.
Definition LogLevel.hpp:14