Logger System 0.1.3
High-performance C++20 thread-safe logging system with asynchronous capabilities
Loading...
Searching...
No Matches
base_writer.cpp
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
15
16namespace kcenon::logger {
17
18base_writer::base_writer(std::unique_ptr<log_formatter_interface> formatter)
19 : formatter_(std::move(formatter)) {
20 if (!formatter_) {
21 // Default to timestamp_formatter if none provided
22 formatter_ = std::make_unique<timestamp_formatter>();
23 }
24
25 // Apply color setting from legacy API to formatter
26 auto opts = formatter_->get_options();
27 opts.use_colors = use_color_;
28 formatter_->set_options(opts);
29}
30
34
35std::string base_writer::format_log_entry(const log_entry& entry) const {
36 if (!formatter_) {
37 // Fallback if formatter is somehow null
38 return entry.message.to_string();
39 }
40 return formatter_->format(entry);
41}
42
43} // namespace kcenon::logger
Abstract base class for all log output writers kcenon.
base_writer(std::unique_ptr< log_formatter_interface > formatter=nullptr)
Constructor with optional formatter.
log_formatter_interface * get_formatter() const
Get the current formatter.
std::string format_log_entry(const log_entry &entry) const
Format a log entry using the current formatter.
std::unique_ptr< log_formatter_interface > formatter_
Abstract interface for log message formatters.
std::string to_string() const
Convert to std::string.
Represents a single log entry with all associated metadata.
Definition log_entry.h:155
small_string_256 message
The actual log message.
Definition log_entry.h:169
Default human-readable formatter with timestamps kcenon.