quill
Public Member Functions | List of all members
FileSinkConfig Class Reference

The FileSinkConfig class holds the configuration options for the FileSink. More...

#include <FileSink.h>

Inheritance diagram for FileSinkConfig:
Inheritance graph
[legend]

Public Member Functions

QUILL_ATTRIBUTE_COLD void set_filename_append_option (FilenameAppendOption value, std::string_view append_filename_format_pattern=std::string_view{})
 Sets the append type for the file name. More...
 
QUILL_ATTRIBUTE_COLD void set_timezone (Timezone time_zone)
 Sets the timezone to use for time-based operations e.g. More...
 
QUILL_ATTRIBUTE_COLD void set_fsync_enabled (bool value)
 Sets whether fsync should be performed when flushing. More...
 
QUILL_ATTRIBUTE_COLD void set_open_mode (char open_mode)
 Sets the open mode for the file. More...
 
QUILL_ATTRIBUTE_COLD void set_write_buffer_size (size_t value)
 Sets the user-defined buffer size for fwrite operations. More...
 
QUILL_ATTRIBUTE_COLD void set_minimum_fsync_interval (std::chrono::milliseconds value)
 Sets the minimum interval between fsync calls. More...
 
QUILL_ATTRIBUTE_COLD void set_override_pattern_formatter_options (std::optional< PatternFormatterOptions > const &options)
 Sets custom pattern formatter options for this sink. More...
 
QUILL_NODISCARD bool fsync_enabled () const noexcept
 Getters.
 
QUILL_NODISCARD Timezone timezone () const noexcept
 
QUILL_NODISCARD FilenameAppendOption filename_append_option () const noexcept
 
QUILL_NODISCARD std::string const & append_filename_format_pattern () const noexcept
 
QUILL_NODISCARD std::string const & open_mode () const noexcept
 
QUILL_NODISCARD size_t write_buffer_size () const noexcept
 
QUILL_NODISCARD std::chrono::milliseconds minimum_fsync_interval () const noexcept
 
QUILL_NODISCARD std::optional< PatternFormatterOptions > const & override_pattern_formatter_options () const noexcept
 

Detailed Description

The FileSinkConfig class holds the configuration options for the FileSink.

Member Function Documentation

◆ set_filename_append_option()

QUILL_ATTRIBUTE_COLD void FileSinkConfig::set_filename_append_option ( FilenameAppendOption  value,
std::string_view  append_filename_format_pattern = std::string_view{} 
)
inline

Sets the append type for the file name.

Possible append types are: StartDate, StartDateTime or None. When this option is set, the file name will be appended with the start date or date and time timestamp of when the process started.

For example: application.log -> application_20230101.log (StartDate) application.log -> application_20230101_121020.log (StartDateTime)

Parameters
valueThe append type to set. Valid options are Date and DateAndTime.
append_filename_format_patternSpecifies a custom strftime format pattern to use for the filename. This parameter is only applicable when FilenameAppendOption::CustomDateTimeFormat is selected

◆ set_fsync_enabled()

QUILL_ATTRIBUTE_COLD void FileSinkConfig::set_fsync_enabled ( bool  value)
inline

Sets whether fsync should be performed when flushing.

The default value is false.

Parameters
valueTrue to perform fsync, false otherwise.

◆ set_minimum_fsync_interval()

QUILL_ATTRIBUTE_COLD void FileSinkConfig::set_minimum_fsync_interval ( std::chrono::milliseconds  value)
inline

Sets the minimum interval between fsync calls.

This specifies the minimum time between consecutive fsync operations but does not guarantee that fsync will be called exactly at that interval.

For example, if some messages are flushed to the log and fsync is skipped because it was previously called, and no further messages are written to the file, fsync will not be called even if the minimum interval has passed. This is because the previous call was skipped due to the interval, and no new messages necessitate another fsync call.

This feature is intended to mitigate concerns about frequent fsync calls potentially causing disk wear.

Note: This option is only applicable when fsync is enabled. By default, the value is 0, which means that fsync will be called periodically by the backend worker thread when messages are written to the file, irrespective of the interval.

Parameters
valueThe minimum interval, in milliseconds, between fsync calls.

◆ set_open_mode()

QUILL_ATTRIBUTE_COLD void FileSinkConfig::set_open_mode ( char  open_mode)
inline

Sets the open mode for the file.

Valid options for the open mode are 'a' or 'w'. The default value is 'a'.

Parameters
open_modeopen mode for the file.

◆ set_override_pattern_formatter_options()

QUILL_ATTRIBUTE_COLD void FileSinkConfig::set_override_pattern_formatter_options ( std::optional< PatternFormatterOptions > const &  options)
inline

Sets custom pattern formatter options for this sink.

By default, the logger's pattern formatter is used to format log messages. This function allows overriding the default formatter with custom options for this specific sink. If a custom formatter is provided, it will be used instead of the logger's formatter.

Parameters
optionsThe custom pattern formatter options to use

◆ set_timezone()

QUILL_ATTRIBUTE_COLD void FileSinkConfig::set_timezone ( Timezone  time_zone)
inline

Sets the timezone to use for time-based operations e.g.

when appending the date to the get_filename or when setting the logging pattern. Valid options for the timezone are 'LocalTime' or 'GmtTime' The default value is 'LocalTime'

Parameters
time_zoneThe timezone to use for time-based operations.

◆ set_write_buffer_size()

QUILL_ATTRIBUTE_COLD void FileSinkConfig::set_write_buffer_size ( size_t  value)
inline

Sets the user-defined buffer size for fwrite operations.

This function allows you to specify a custom buffer size for fwrite, improving efficiency for file write operations.

To disable custom buffering and revert to the default size, pass a value of 0.

Note
By default, a buffer size of 64 KB is used.
Parameters
valueSize of the buffer in bytes. If set to 0, the default buffer size will be used.

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