Logger System 0.1.3
High-performance C++20 thread-safe logging system with asynchronous capabilities
Loading...
Searching...
No Matches
thread_safe_writer.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2025, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
5#pragma once
6
7#include "base_writer.h"
8
10
11#include <mutex>
12
54namespace kcenon::logger {
55
82public:
89 explicit thread_safe_writer(std::unique_ptr<log_formatter_interface> formatter = nullptr);
90
94 ~thread_safe_writer() override = default;
95
96 // Non-copyable and non-movable (mutex cannot be copied or moved)
101
117 common::VoidResult write(const log_entry& entry) final;
118
128 common::VoidResult flush() final;
129
130protected:
145 virtual common::VoidResult write_entry_impl(const log_entry& entry) = 0;
146
159 virtual common::VoidResult flush_impl() = 0;
160
174 std::mutex& get_mutex() const { return write_mutex_; }
175
176private:
178 mutable std::mutex write_mutex_;
179};
180
181} // namespace kcenon::logger
Abstract base class for all log output writers kcenon.
Abstract base class for all log output writers.
Definition base_writer.h:95
Base class providing automatic thread-safety for writer implementations.
thread_safe_writer & operator=(thread_safe_writer &&)=delete
thread_safe_writer(const thread_safe_writer &)=delete
thread_safe_writer & operator=(const thread_safe_writer &)=delete
thread_safe_writer(thread_safe_writer &&)=delete
~thread_safe_writer() override=default
Virtual destructor.
DLL export/import macros for logger_system shared library support.
#define LOGGER_SYSTEM_API
Represents a single log entry with all associated metadata.
Definition log_entry.h:155