Logger System 0.1.3
High-performance C++20 thread-safe logging system with asynchronous capabilities
Loading...
Searching...
No Matches
filtered_logger.h
Go to the documentation of this file.
1// BSD 3-Clause License
2
10#pragma once
11
12#include <memory>
13#include <string>
14
17#include <kcenon/common/interfaces/logger_interface.h>
18
20
21// Type alias for log_level
22using log_level = common::interfaces::log_level;
23
24template<log_level MinLevel = log_level::info>
26public:
27 explicit filtered_logger(std::shared_ptr<kcenon::logger::logger> impl)
28 : logger_(std::move(impl)) {}
29
30 void log(log_level level,
31 const std::string& message,
32 const log_context& context) const {
33 if (!logger_) {
34 return;
35 }
36 if (static_cast<int>(level) < static_cast<int>(MinLevel)) {
37 return;
38 }
39 logger_->log(level, message,
40 std::string(context.file),
41 context.line,
42 std::string(context.function));
43 }
44
45 template<log_level Level>
46 void log(const std::string& message, const log_context& context) const {
47 if constexpr (static_cast<int>(Level) >= static_cast<int>(MinLevel)) {
48 if (logger_) {
49 logger_->log(Level, message,
50 std::string(context.file),
51 context.line,
52 std::string(context.function));
53 }
54 }
55 }
56
57private:
58 std::shared_ptr<kcenon::logger::logger> logger_;
59};
60
61} // namespace kcenon::logger::core
void log(log_level level, const std::string &message, const log_context &context) const
void log(const std::string &message, const log_context &context) const
std::shared_ptr< kcenon::logger::logger > logger_
filtered_logger(std::shared_ptr< kcenon::logger::logger > impl)
common::VoidResult log(common::interfaces::log_level level, const std::string &message) override
Log a message with specified level (ILogger interface)
Definition logger.cpp:378
Structured log context with key-value metadata for correlation.
High-performance, thread-safe logging system with asynchronous capabilities.
Log context containing source location information.
Definition core.cppm:91