quill
Public Member Functions | Protected Attributes | Static Protected Attributes | Friends | List of all members
detail::LoggerBase Class Reference
Inheritance diagram for detail::LoggerBase:
Inheritance graph
[legend]
Collaboration diagram for detail::LoggerBase:
Collaboration graph
[legend]

Public Member Functions

 LoggerBase (std::string logger_name, std::vector< std::shared_ptr< Sink >> sinks, PatternFormatterOptions pattern_formatter_options, ClockSourceType clock_source, UserClockSource *user_clock)
 
 LoggerBase (LoggerBase const &)=delete
 
LoggerBaseoperator= (LoggerBase const &)=delete
 
QUILL_NODISCARD std::string const & get_logger_name () const noexcept
 Returns the name of the logger. More...
 
QUILL_NODISCARD UserClockSourceget_user_clock_source () const noexcept
 Returns the user-defined clock source. More...
 
QUILL_NODISCARD ClockSourceType get_clock_source_type () const noexcept
 Returns the type of clock source being used. More...
 
QUILL_NODISCARD PatternFormatterOptions const & get_pattern_formatter_options () const noexcept
 Returns the pattern formatter options. More...
 
QUILL_NODISCARD std::vector< std::shared_ptr< Sink > > const & get_sinks () const noexcept
 Returns a const reference to the sinks vector. More...
 
void mark_invalid ()
 This function sets the logger's validity flag to false, indicating that the logger is no longer valid.
 
QUILL_NODISCARD bool is_valid_logger () const noexcept
 Checks if the logger is valid. More...
 
QUILL_NODISCARD LogLevel get_log_level () const noexcept
 
void set_log_level (LogLevel new_log_level)
 Set the log level of the logger. More...
 
void set_immediate_flush (uint32_t flush_every_n_messages=1)
 Sets the flush interval for logging based on message count. More...
 
template<LogLevel log_statement_level>
QUILL_NODISCARD QUILL_ATTRIBUTE_HOT bool should_log_statement () const noexcept
 Checks if the given log_statement_level can be logged by this logger. More...
 
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. More...
 

Protected Attributes

std::string _logger_name
 
UserClockSource_user_clock {nullptr}
 
std::atomic< uint32_t > _message_flush_threshold {0}
 
std::atomic< uint32_t > _messages_since_last_flush {0}
 
ClockSourceType _clock_source
 
std::atomic< LogLevel > _log_level {LogLevel::Info}
 
std::atomic< LogLevel > _backtrace_flush_level {LogLevel::None}
 
std::atomic< bool > _valid {true}
 Updated by the frontend at any time, accessed by the backend.
 
PatternFormatterOptions _pattern_formatter_options
 
std::vector< std::shared_ptr< Sink > > _sinks
 
std::shared_ptr< PatternFormatter_pattern_formatter
 
std::shared_ptr< BacktraceStorage_backtrace_storage
 

Static Protected Attributes

static QUILL_THREAD_LOCAL ThreadContext_thread_context = nullptr
 

Friends

class BackendWorker
 
class LoggerManager
 

Member Function Documentation

◆ get_clock_source_type()

QUILL_NODISCARD ClockSourceType detail::LoggerBase::get_clock_source_type ( ) const
inlinenoexcept

Returns the type of clock source being used.

Returns
The ClockSourceType enum value representing the current clock source.

◆ get_log_level()

QUILL_NODISCARD LogLevel detail::LoggerBase::get_log_level ( ) const
inlinenoexcept
Returns
The log level of the logger

◆ get_logger_name()

QUILL_NODISCARD std::string const& detail::LoggerBase::get_logger_name ( ) const
inlinenoexcept

Returns the name of the logger.

Returns
A constant reference to the logger's name.

◆ get_pattern_formatter_options()

QUILL_NODISCARD PatternFormatterOptions const& detail::LoggerBase::get_pattern_formatter_options ( ) const
inlinenoexcept

Returns the pattern formatter options.

Returns
A constant reference to the PatternFormatterOptions object.

◆ get_sinks()

QUILL_NODISCARD std::vector<std::shared_ptr<Sink> > const& detail::LoggerBase::get_sinks ( ) const
inlinenoexcept

Returns a const reference to the sinks vector.

Warning
The returned sinks should be treated as read-only. Do not modify the Sink objects as they are used by the backend thread
Returns
A constant reference to the std::vector<std::shared_ptr<Sink>> object

◆ get_user_clock_source()

QUILL_NODISCARD UserClockSource* detail::LoggerBase::get_user_clock_source ( ) const
inlinenoexcept

Returns the user-defined clock source.

Returns
A pointer to the constant UserClockSource object.

◆ is_valid_logger()

QUILL_NODISCARD bool detail::LoggerBase::is_valid_logger ( ) const
inlinenoexcept

Checks if the logger is valid.

Returns
True if the logger is valid, false otherwise.

◆ set_immediate_flush()

void detail::LoggerBase::set_immediate_flush ( uint32_t  flush_every_n_messages = 1)
inline

Sets the flush interval for logging based on message count.

When enabled, this will automatically call flush_log after the specified number of messages have been logged

This is particularly valuable when:

  • Running the application in a debugger, pass flush_every_n_messages == 1
  • Requiring synchronized logging for debugging, pass flush_every_n_messages == 1
  • Dropping messages in a high-throughput simulation when using BoundedQueue, that you normally wouldn't drop in production environment
Warning
Enabling immediate flush can significantly impact application performance and should only be used during debugging. It is disabled by default.
Parameters
flush_every_n_messagesnumber of messages before auto-flush (0 to disable)

◆ set_log_level()

void detail::LoggerBase::set_log_level ( LogLevel  new_log_level)
inline

Set the log level of the logger.

Parameters
new_log_levelThe new log level

◆ should_log_statement() [1/2]

template<LogLevel log_statement_level>
QUILL_NODISCARD QUILL_ATTRIBUTE_HOT bool detail::LoggerBase::should_log_statement ( ) const
inlinenoexcept

Checks if the given log_statement_level can be logged by this logger.

Returns
bool if a statement can be logged based on the current log level

◆ should_log_statement() [2/2]

QUILL_NODISCARD QUILL_ATTRIBUTE_HOT bool detail::LoggerBase::should_log_statement ( LogLevel  log_statement_level) const
inlinenoexcept

Checks if the given log_statement_level can be logged by this logger.

Parameters
log_statement_levelThe log level of the log statement to be logged
Returns
bool if a statement can be logged based on the current log level

The documentation for this class was generated from the following file: