Logger System 1.0.0
High-performance C++20 thread-safe logging system with asynchronous capabilities
Loading...
Searching...
No Matches
console_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
12#pragma once
13
17
19
20#include <atomic>
21#include <mutex>
22#include <memory>
23
24namespace kcenon::logger {
25
26namespace security { class integrity_policy; }
27
49public:
56 explicit console_writer(bool use_stderr = false,
57 bool auto_detect_color = true,
58 std::unique_ptr<log_formatter_interface> formatter = nullptr);
59
63 ~console_writer() override;
64
65 // Non-copyable and non-movable
70
76 common::VoidResult write(const log_entry& entry) override;
77
82 common::VoidResult flush() override;
83
87 std::string get_name() const override { return "console"; }
88
92 bool is_healthy() const override;
93
98 void set_use_stderr(bool use_stderr);
99
104 void set_use_color(bool use_color);
105
110 bool use_color() const;
111
120 void set_integrity_policy(std::shared_ptr<security::integrity_policy> policy);
121
122protected:
126 std::string format_entry(const log_entry& entry) const;
127
132 std::mutex& get_mutex() const { return mutex_; }
133
134private:
139 bool is_color_supported() const;
140
141private:
143 bool use_color_{true};
144 std::unique_ptr<log_formatter_interface> formatter_;
145 std::shared_ptr<security::integrity_policy> integrity_policy_;
146 mutable std::mutex mutex_;
147};
148
149} // namespace kcenon::logger
Core console writer for logging to stdout/stderr.
console_writer & operator=(const console_writer &)=delete
std::shared_ptr< security::integrity_policy > integrity_policy_
console_writer & operator=(console_writer &&)=delete
std::unique_ptr< log_formatter_interface > formatter_
std::mutex & get_mutex() const
Access the writer mutex for extended operations.
console_writer(const console_writer &)=delete
std::string get_name() const override
Get writer name.
console_writer(console_writer &&)=delete
Base interface for all log writers and decorators.
Interface for log message formatters (Strategy Pattern) kcenon.
Base interface for all log writers and decorators.
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
Tag interface for synchronous writers.
Writer category interfaces and type traits kcenon.