quill
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
StreamSink Class Reference

StreamSink class for handling log messages. More...

#include <StreamSink.h>

Inheritance diagram for StreamSink:
Inheritance graph
[legend]
Collaboration diagram for StreamSink:
Collaboration graph
[legend]

Public Member Functions

 StreamSink (fs::path stream, FILE *file=nullptr, std::optional< PatternFormatterOptions > const &override_pattern_formatter_options=std::nullopt, FileEventNotifier file_event_notifier=FileEventNotifier{})
 Constructor for StreamSink. More...
 
QUILL_ATTRIBUTE_HOT void write_log (MacroMetadata const *, uint64_t, std::string_view, std::string_view, std::string const &, std::string_view, LogLevel, std::string_view, std::string_view, std::vector< std::pair< std::string, std::string >> const *, std::string_view, std::string_view log_statement) override
 Writes a formatted log message to the stream.
 
QUILL_ATTRIBUTE_HOT void flush_sink () override
 Flushes the stream.
 
virtual QUILL_NODISCARD fs::path const & get_filename () const noexcept
 Returns the name of the file. More...
 
QUILL_NODISCARD bool is_null () const noexcept
 Checks if the stream is null. More...
 
- Public Member Functions inherited from Sink
 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...
 

Static Public Member Functions

static QUILL_ATTRIBUTE_HOT void safe_fwrite (void const *ptr, size_t size, size_t count, FILE *stream)
 Writes data safely to the stream. More...
 

Protected Member Functions

QUILL_ATTRIBUTE_HOT void flush ()
 Flushes the stream.
 
- Protected Member Functions inherited from Sink
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...
 

Protected Attributes

fs::path _filename
 
FILE * _file {nullptr}
 
size_t _file_size {0}
 The current file size.
 
FileEventNotifier _file_event_notifier
 
bool _is_null {false}
 
bool _write_occurred {false}
 

Detailed Description

StreamSink class for handling log messages.

Constructor & Destructor Documentation

◆ StreamSink()

StreamSink::StreamSink ( fs::path  stream,
FILE *  file = nullptr,
std::optional< PatternFormatterOptions > const &  override_pattern_formatter_options = std::nullopt,
FileEventNotifier  file_event_notifier = FileEventNotifier{} 
)
inlineexplicit

Constructor for StreamSink.

Parameters
streamThe stream type (stdout, stderr, or file)
override_pattern_formatter_optionsoverride the logger pattern formatter
fileFile pointer for file-based stream
file_event_notifierNotifies on file events
Exceptions
QuillErrorif an invalid parameter is provided

Member Function Documentation

◆ get_filename()

virtual QUILL_NODISCARD fs::path const& StreamSink::get_filename ( ) const
inlinevirtualnoexcept

Returns the name of the file.

Returns
The name of the file

◆ is_null()

QUILL_NODISCARD bool StreamSink::is_null ( ) const
inlinenoexcept

Checks if the stream is null.

Returns
True if the stream is null, false otherwise

◆ safe_fwrite()

static QUILL_ATTRIBUTE_HOT void StreamSink::safe_fwrite ( void const *  ptr,
size_t  size,
size_t  count,
FILE *  stream 
)
inlinestatic

Writes data safely to the stream.

Parameters
ptrPointer to the data to be written
sizeSize of each element to be written
countNumber of elements to write
streamThe stream to write to

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