Logger System 0.1.3
High-performance C++20 thread-safe logging system with asynchronous capabilities
Loading...
Searching...
No Matches
log_server.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2021-2025, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
10#pragma once
11
13#include <string>
14#include <memory>
15#include <vector>
16#include <atomic>
17#include <thread>
18
20
25 std::string host = "localhost";
26 uint16_t port = 9999;
27 size_t max_connections = 100;
28 size_t buffer_size = 8192;
29 bool enable_compression = false;
30 bool enable_encryption = false;
31};
32
37private:
39 std::atomic<bool> running_{false};
40 std::vector<std::thread> worker_threads_;
41
42public:
43 explicit log_server(const server_config& config = {}) : config_(config) {}
44
46 stop();
47 }
48
52 bool start() {
53 if (running_.load()) {
54 return false;
55 }
56
57 running_.store(true);
58
59 // Start worker threads
60 for (size_t i = 0; i < std::thread::hardware_concurrency(); ++i) {
61 worker_threads_.emplace_back([this]() {
63 });
64 }
65
66 return true;
67 }
68
72 void stop() {
73 if (!running_.load()) {
74 return;
75 }
76
77 running_.store(false);
78
79 for (auto& thread : worker_threads_) {
80 if (thread.joinable()) {
81 thread.join();
82 }
83 }
84 worker_threads_.clear();
85 }
86
90 bool is_running() const {
91 return running_.load();
92 }
93
97 const server_config& get_config() const {
98 return config_;
99 }
100
101private:
102 void worker_loop() {
103 while (running_.load()) {
104 // Worker implementation would go here
105 // For now, just sleep to simulate work
106 std::this_thread::sleep_for(std::chrono::milliseconds(100));
107 }
108 }
109};
110
115public:
119 static std::unique_ptr<log_server> create_basic(const server_config& config = {}) {
120 return std::make_unique<log_server>(config);
121 }
122
126 static std::unique_ptr<log_server> create_default() {
127 return create_basic();
128 }
129};
130
131} // namespace kcenon::logger::server
Factory for creating log servers.
Definition log_server.h:114
static std::unique_ptr< log_server > create_basic(const server_config &config={})
Create a basic log server.
Definition log_server.h:119
static std::unique_ptr< log_server > create_default()
Create a log server with default configuration.
Definition log_server.h:126
Log server for receiving distributed log messages.
Definition log_server.h:36
std::vector< std::thread > worker_threads_
Definition log_server.h:40
bool start()
Start the log server.
Definition log_server.h:52
void stop()
Stop the log server.
Definition log_server.h:72
log_server(const server_config &config={})
Definition log_server.h:43
bool is_running() const
Check if server is running.
Definition log_server.h:90
const server_config & get_config() const
Get server configuration.
Definition log_server.h:97
Common types and enumerations for logger system.
Configuration for log server.
Definition log_server.h:24