9 #include "quill/core/Attributes.h" 10 #include "quill/core/Common.h" 11 #include "quill/core/LogLevel.h" 12 #include "quill/core/PatternFormatterOptions.h" 13 #include "quill/core/QuillError.h" 14 #include "quill/core/ThreadContextManager.h" 32 class BacktraceStorage;
40 LoggerBase(std::string logger_name, std::vector<std::shared_ptr<Sink>> sinks,
43 : _logger_name(static_cast<std::string&&>(logger_name)),
44 _user_clock(user_clock),
45 _clock_source(clock_source),
46 _pattern_formatter_options(static_cast<PatternFormatterOptions&&>(pattern_formatter_options))
49 for (
auto const& sink : sinks)
51 assert(sink &&
"sink pointer is nullptr");
55 this->_sinks =
static_cast<std::vector<std::shared_ptr<Sink>
>&&>(sinks);
69 QUILL_NODISCARD std::string
const&
get_logger_name() const noexcept {
return _logger_name; }
89 return _pattern_formatter_options;
97 QUILL_NODISCARD std::vector<std::shared_ptr<Sink>>
const&
get_sinks() const noexcept
113 return _valid.load(std::memory_order_acquire);
121 return _log_level.load(std::memory_order_relaxed);
130 if (QUILL_UNLIKELY(new_log_level == LogLevel::Backtrace))
132 QUILL_THROW(
QuillError{
"LogLevel::Backtrace is only used internally. Please don't use it."});
135 _log_level.store(new_log_level, std::memory_order_relaxed);
156 _message_flush_threshold.store(flush_every_n_messages, std::memory_order_relaxed);
163 template <LogLevel log_statement_level>
183 static inline QUILL_THREAD_LOCAL
ThreadContext* _thread_context =
nullptr;
186 std::string _logger_name;
188 std::atomic<uint32_t> _message_flush_threshold{0};
189 std::atomic<uint32_t> _messages_since_last_flush{0};
190 ClockSourceType _clock_source;
191 std::atomic<LogLevel> _log_level{LogLevel::Info};
192 std::atomic<LogLevel> _backtrace_flush_level{LogLevel::None};
197 std::vector<std::shared_ptr<Sink>> _sinks;
198 std::shared_ptr<PatternFormatter> _pattern_formatter;
199 std::shared_ptr<BacktraceStorage> _backtrace_storage;
QUILL_NODISCARD QUILL_ATTRIBUTE_HOT bool should_log_statement() const noexcept
Checks if the given log_statement_level can be logged by this logger.
Definition: LoggerBase.h:164
QUILL_NODISCARD QUILL_ATTRIBUTE_HOT bool should_log_statement(LogLevel log_statement_level) const noexcept
Checks if the given log_statement_level can be logged by this logger.
Definition: LoggerBase.h:174
QUILL_NODISCARD std::string const & get_logger_name() const noexcept
Returns the name of the logger.
Definition: LoggerBase.h:69
std::atomic< bool > _valid
Updated by the frontend at any time, accessed by the backend.
Definition: LoggerBase.h:193
Base class for sinks.
Definition: Sink.h:40
QUILL_NODISCARD ClockSourceType get_clock_source_type() const noexcept
Returns the type of clock source being used.
Definition: LoggerBase.h:81
QUILL_NODISCARD PatternFormatterOptions const & get_pattern_formatter_options() const noexcept
Returns the pattern formatter options.
Definition: LoggerBase.h:87
QUILL_NODISCARD bool is_valid_logger() const noexcept
Checks if the logger is valid.
Definition: LoggerBase.h:111
Setups a signal handler to handle fatal signals.
Definition: BackendManager.h:24
void set_immediate_flush(uint32_t flush_every_n_messages=1)
Sets the flush interval for logging based on message count.
Definition: LoggerBase.h:154
QUILL_NODISCARD std::vector< std::shared_ptr< Sink > > const & get_sinks() const noexcept
Returns a const reference to the sinks vector.
Definition: LoggerBase.h:97
Definition: LoggerBase.h:36
QUILL_NODISCARD LogLevel get_log_level() const noexcept
Definition: LoggerBase.h:119
custom exception
Definition: QuillError.h:45
void set_log_level(LogLevel new_log_level)
Set the log level of the logger.
Definition: LoggerBase.h:128
Base class that provides a timestamp for log statements based on a user-provided clock source...
Definition: UserClockSource.h:25
QUILL_NODISCARD UserClockSource * get_user_clock_source() const noexcept
Returns the user-defined clock source.
Definition: LoggerBase.h:75
Definition: BackendWorker.h:72
Definition: LoggerManager.h:34
void mark_invalid()
This function sets the logger's validity flag to false, indicating that the logger is no longer valid...
Definition: LoggerBase.h:105
Definition: ThreadContextManager.h:48