A custom rotating file sink that formats and logs messages to a file with automatic rotation based on file size or time interval. This class extends quill::RotatingFileSink
and provides the ability to format log messages using a pattern and time format, ensuring that logs are written to a rotating file system.
More...
#include <AutonomyLogging.h>
|
| MRDTRotatingFileSink (const quill::fs::path &qFilename, const quill::RotatingFileSinkConfig &qConfig, const std::string &szFormatPattern, const std::string &szTimeFormat, quill::Timezone qTimestampTimezone=quill::Timezone::LocalTime, quill::FileEventNotifier qFileEventNotifier=quill::FileEventNotifier{}) |
| Constructs a new MRDTRotatingFileSink object with specified formatting, file rotation settings, and an optional file event notifier. This constructor initializes the sink with a log message pattern, timestamp format, and configuration for rotating the log file based on size or time interval.
|
|
void | write_log (const quill::MacroMetadata *qLogMetadata, uint64_t unLogTimestamp, std::string_view szThreadID, std::string_view szThreadName, const std::string &szProcessID, std::string_view szLoggerName, quill::LogLevel qLogLevel, std::string_view szLogLevelDescription, std::string_view szLogLevelShortCode, const std::vector< std::pair< std::string, std::string > > *vNamedArgs, std::string_view szLogMessage, std::string_view) override |
| Writes a log message to the MRDT rotating file sink. The log message is first formatted using a custom formatter, and then the formatted message along with the original log details are passed to the base class (RotatingFileSink) for further handling (such as writing to a rotating log file).
|
|
|
quill::PatternFormatter | qFormatter |
|
A custom rotating file sink that formats and logs messages to a file with automatic rotation based on file size or time interval. This class extends quill::RotatingFileSink
and provides the ability to format log messages using a pattern and time format, ensuring that logs are written to a rotating file system.
This class is ideal for scenarios where log files need to be managed based on size or time constraints, such as in long-running applications. It formats the log messages before writing them to files, making it easy to store logs with consistent formatting while preventing file bloat through rotation.
Key Features:
- Customizable log message formats using a pattern.
- Automatic file rotation based on configurable size or time intervals.
- Supports different timestamp formats and timezones for log entries.
- Inherits from
quill::RotatingFileSink
for easy integration with Quill's logging framework.
- Note
- This class is designed to handle file-based logging with automatic rotation, making it suitable for use in both development and production environments.
- See also
- quill::RotatingFileSink
-
quill::PatternFormatter
- Author
- Eli Byrd (edbgk.nosp@m.k@ms.nosp@m.t.edu)
- Date
- 2024-08-16
◆ MRDTRotatingFileSink()
logging::MRDTRotatingFileSink::MRDTRotatingFileSink |
( |
const quill::fs::path & |
qFilename, |
|
|
const quill::RotatingFileSinkConfig & |
qConfig, |
|
|
const std::string & |
szFormatPattern, |
|
|
const std::string & |
szTimeFormat, |
|
|
quill::Timezone |
qTimestampTimezone = quill::Timezone::LocalTime , |
|
|
quill::FileEventNotifier |
qFileEventNotifier = quill::FileEventNotifier{} |
|
) |
| |
|
inline |
Constructs a new MRDTRotatingFileSink object with specified formatting, file rotation settings, and an optional file event notifier. This constructor initializes the sink with a log message pattern, timestamp format, and configuration for rotating the log file based on size or time interval.
- Parameters
-
qFilename | - The path to the log file. |
qConfig | - The configuration for rotating the log file (e.g., based on size or time). |
szFormatPattern | - The pattern used to format the log message. |
szTimeFormat | - The format of the timestamp in the log message. |
qTimestampTimezone | - The timezone used for the timestamp (default: LocalTime). |
qFileEventNotifier | - Optional event notifier for file-related events (default: none). |
- Note
- Ensure that the file rotation configuration (
config
) is correctly set up to avoid unexpected log file behavior. The format pattern and time format should also be defined correctly to ensure logs are written with the intended structure.
- Warning
- Misconfiguration of file rotation settings or format patterns may result in loss of log data or malformed log outputs.
- See also
- quill::RotatingFileSink
-
quill::PatternFormatter
- Author
- Eli Byrd (edbgk.nosp@m.k@ms.nosp@m.t.edu)
- Date
- 2024-08-16
352 {}
353 ) :
354 quill::RotatingFileSink(qFilename, qConfig, qFileEventNotifier),
355 qFormatter(quill::PatternFormatterOptions(szFormatPattern, szTimeFormat, qTimestampTimezone))
356 {}
◆ write_log()
void logging::MRDTRotatingFileSink::write_log |
( |
const quill::MacroMetadata * |
qLogMetadata, |
|
|
uint64_t |
unLogTimestamp, |
|
|
std::string_view |
szThreadID, |
|
|
std::string_view |
szThreadName, |
|
|
const std::string & |
szProcessID, |
|
|
std::string_view |
szLoggerName, |
|
|
quill::LogLevel |
qLogLevel, |
|
|
std::string_view |
szLogLevelDescription, |
|
|
std::string_view |
szLogLevelShortCode, |
|
|
const std::vector< std::pair< std::string, std::string > > * |
vNamedArgs, |
|
|
std::string_view |
szLogMessage, |
|
|
std::string_view |
|
|
) |
| |
|
override |
Writes a log message to the MRDT rotating file sink. The log message is first formatted using a custom formatter, and then the formatted message along with the original log details are passed to the base class (RotatingFileSink) for further handling (such as writing to a rotating log file).
- Parameters
-
qLogMetadata | - Metadata about the log statement (e.g., file, line number). |
unLogTimestamp | - The timestamp of the log statement. |
szThreadID | - The ID of the thread that generated the log. |
szThreadName | - The name of the thread that generated the log. |
szProcessID | - The ID of the process that generated the log. |
szLoggerName | - The name of the logger that generated the log. |
qLogLevel | - The level/severity of the log statement. |
szLogLevelDescription | - A description of the log level. |
szLogLevelShortCode | - A short code representing the log level. |
vNamedArgs | - Optional named arguments passed with the log statement. |
szLogMessage | - The actual log message content. |
- Note
- This method formats the log message using the provided formatter, ensuring that the final output adheres to the defined format pattern. The formatted message is then handled by the rotating file sink for writing to a file that rotates based on file size or time interval.
-
This method should not be called directly. It is meant to be invoked by the logging framework as part of the log handling process.
- See also
- quill::RotatingFileSink
- Warning
- Ensure that the formatter is correctly configured and that the rotating file sink is properly set up to avoid loss of log data.
- Attention
- This method overrides the base class's write_log function to inject custom formatting logic while preserving the core file logging functionality.
- Author
- Eli Byrd (edbgk.nosp@m.k@ms.nosp@m.t.edu)
- Date
- 2024-08-16
308 {
309
310 std::string_view szFormattedLogMessage = qFormatter.format(unLogTimestamp,
311 szThreadID,
312 szThreadName,
313 szProcessID,
314 szLoggerName,
315 szLogLevelDescription,
316 szLogLevelShortCode,
317 *qLogMetadata,
318 vNamedArgs,
319 szLogMessage
320 );
321
322
323 if (static_cast<int>(g_eFileLogLevel) <= static_cast<int>(qLogLevel))
324 {
325 quill::RotatingFileSink::write_log(qLogMetadata,
326 unLogTimestamp,
327 szThreadID,
328 szThreadName,
329 szProcessID,
330 szLoggerName,
331 qLogLevel,
332 szLogLevelDescription,
333 szLogLevelShortCode,
334 vNamedArgs,
335 szLogMessage,
336 szFormattedLogMessage
337 );
338 }
339 }
The documentation for this class was generated from the following files: