quill
Public Member Functions | Protected Member Functions | Friends | List of all members
Sink Class Referenceabstract

Base class for sinks. More...

#include <Sink.h>

Inheritance diagram for Sink:
Inheritance graph
[legend]

Public Member Functions

 Sink (std::optional< PatternFormatterOptions > override_pattern_formatter_options=std::nullopt)
 Constructor Uses the default pattern formatter.
 
virtual ~Sink ()=default
 Destructor.
 
 Sink (Sink const &)=delete
 
Sinkoperator= (Sink const &)=delete
 
void set_log_level_filter (LogLevel log_level)
 Sets a log level filter on the sink. More...
 
QUILL_NODISCARD LogLevel get_log_level_filter () const noexcept
 Returns the current log level filter set on the sink. More...
 
void add_filter (std::unique_ptr< Filter > filter)
 Adds a new filter to the sink. More...
 

Protected Member Functions

virtual QUILL_ATTRIBUTE_HOT void write_log (MacroMetadata const *log_metadata, uint64_t log_timestamp, std::string_view thread_id, std::string_view thread_name, std::string const &process_id, std::string_view logger_name, LogLevel log_level, std::string_view log_level_description, std::string_view log_level_short_code, std::vector< std::pair< std::string, std::string >> const *named_args, std::string_view log_message, std::string_view log_statement)=0
 Logs a formatted log message to the sink. More...
 
virtual QUILL_ATTRIBUTE_HOT void flush_sink ()=0
 Flushes the sink, synchronizing the associated sink with its controlled output sequence.
 
virtual QUILL_ATTRIBUTE_HOT void run_periodic_tasks () noexcept
 Executes periodic tasks by the backend thread, providing an opportunity for the user to perform custom tasks. More...
 
QUILL_NODISCARD bool apply_all_filters (MacroMetadata const *log_metadata, uint64_t log_timestamp, std::string_view thread_id, std::string_view thread_name, std::string_view logger_name, LogLevel log_level, std::string_view log_message, std::string_view log_statement)
 Applies all registered filters to the log record. More...
 

Friends

class detail::BackendWorker
 

Detailed Description

Base class for sinks.

Member Function Documentation

◆ add_filter()

void Sink::add_filter ( std::unique_ptr< Filter filter)
inline

Adds a new filter to the sink.

Note
Thread safe.
Parameters
filterUnique pointer to the filter instance.

◆ apply_all_filters()

QUILL_NODISCARD bool Sink::apply_all_filters ( MacroMetadata const *  log_metadata,
uint64_t  log_timestamp,
std::string_view  thread_id,
std::string_view  thread_name,
std::string_view  logger_name,
LogLevel  log_level,
std::string_view  log_message,
std::string_view  log_statement 
)
inlineprotected

Applies all registered filters to the log record.

Note
Called internally by the backend worker thread.
Parameters
log_metadataPointer to the macro metadata.
log_timestampTimestamp of the log event.
thread_idID of the thread.
thread_nameName of the thread.
logger_nameName of the logger.
log_levelLog level of the message.
log_messageThe log message.
log_statementThe log message.
Returns
True if the log record passes all filters, false otherwise.

◆ get_log_level_filter()

QUILL_NODISCARD LogLevel Sink::get_log_level_filter ( ) const
inlinenoexcept

Returns the current log level filter set on the sink.

Note
Thread safe.
Returns
The current log level filter.

◆ run_periodic_tasks()

virtual QUILL_ATTRIBUTE_HOT void Sink::run_periodic_tasks ( )
inlineprotectedvirtualnoexcept

Executes periodic tasks by the backend thread, providing an opportunity for the user to perform custom tasks.

For example, batch committing to a database, or any other desired periodic operations.

Note
It is recommended to avoid heavy operations within this function as it may affect performance of the backend thread.

◆ set_log_level_filter()

void Sink::set_log_level_filter ( LogLevel  log_level)
inline

Sets a log level filter on the sink.

Note
Thread safe.
Parameters
log_levelThe log level severity.

◆ write_log()

virtual QUILL_ATTRIBUTE_HOT void Sink::write_log ( MacroMetadata const *  log_metadata,
uint64_t  log_timestamp,
std::string_view  thread_id,
std::string_view  thread_name,
std::string const &  process_id,
std::string_view  logger_name,
LogLevel  log_level,
std::string_view  log_level_description,
std::string_view  log_level_short_code,
std::vector< std::pair< std::string, std::string >> const *  named_args,
std::string_view  log_message,
std::string_view  log_statement 
)
protectedpure virtual

Logs a formatted log message to the sink.

Note
Accessor for backend processing.
Parameters
log_metadataPointer to the macro metadata.
log_timestampTimestamp of the log event.
thread_idID of the thread.
thread_nameName of the thread.
process_idProcess Id
logger_nameName of the logger.
log_levelLog level of the message.
log_level_descriptionDescription of the log level.
log_level_short_codeShort code representing the log level.
named_argsVector of key-value pairs of named args
log_messageThe log message.
log_statementThe log statement.

Implemented in ConsoleSink, StreamSink, detail::JsonSink< StreamSink >, detail::JsonSink< FileSink >, NullSink, and CustomJsonFileSink.


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