unilink  0.4.3
A simple C++ library for unified async communication
unilink::diagnostics::LogRotation Class Reference

Log rotation manager. More...

#include <log_rotation.hpp>

Public Member Functions

 LogRotation (const LogRotationConfig &config=LogRotationConfig{})
 Constructor. More...
 
bool should_rotate (const std::string &filepath) const
 Check if current log file needs rotation. More...
 
std::string rotate (const std::string &filepath)
 Perform log rotation. More...
 
void cleanup_old_files (const std::string &base_filepath)
 Clean up old log files. More...
 
std::string get_next_file_path (const std::string &base_filepath) const
 Get next available log file path. More...
 
void update_config (const LogRotationConfig &config)
 Update rotation configuration. More...
 
const LogRotationConfigget_config () const
 Get current configuration. More...
 

Static Public Member Functions

static size_t get_file_size (const std::string &filepath)
 Get file size in bytes. More...
 
static std::vector< std::string > get_log_files (const std::string &base_filepath)
 Get all log files matching pattern. More...
 

Detailed Description

Log rotation manager.

Handles log file rotation based on size and automatic cleanup of old log files based on count limits.

Definition at line 51 of file log_rotation.hpp.

Constructor & Destructor Documentation

◆ LogRotation()

unilink::diagnostics::LogRotation::LogRotation ( const LogRotationConfig config = LogRotationConfig{})
explicit

Constructor.

Parameters
configRotation configuration

Definition at line 27 of file log_rotation.cc.

Member Function Documentation

◆ cleanup_old_files()

void unilink::diagnostics::LogRotation::cleanup_old_files ( const std::string &  base_filepath)

Clean up old log files.

Parameters
base_filepathBase log file path (without index)

Definition at line 64 of file log_rotation.cc.

◆ get_config()

const LogRotationConfig& unilink::diagnostics::LogRotation::get_config ( ) const
inline

Get current configuration.

Definition at line 95 of file log_rotation.hpp.

◆ get_file_size()

size_t unilink::diagnostics::LogRotation::get_file_size ( const std::string &  filepath)
static

Get file size in bytes.

Parameters
filepathFile path to check
Returns
File size in bytes, 0 if file doesn't exist

Definition at line 114 of file log_rotation.cc.

◆ get_log_files()

std::vector< std::string > unilink::diagnostics::LogRotation::get_log_files ( const std::string &  base_filepath)
static

Get all log files matching pattern.

Parameters
base_filepathBase log file path
Returns
Vector of matching log file paths, sorted by modification time

Definition at line 125 of file log_rotation.cc.

◆ get_next_file_path()

std::string unilink::diagnostics::LogRotation::get_next_file_path ( const std::string &  base_filepath) const

Get next available log file path.

Parameters
base_filepathBase log file path
Returns
Next available file path

Definition at line 86 of file log_rotation.cc.

◆ rotate()

std::string unilink::diagnostics::LogRotation::rotate ( const std::string &  filepath)

Perform log rotation.

Parameters
filepathCurrent log file path
Returns
New log file path after rotation

Definition at line 40 of file log_rotation.cc.

◆ should_rotate()

bool unilink::diagnostics::LogRotation::should_rotate ( const std::string &  filepath) const

Check if current log file needs rotation.

Parameters
filepathCurrent log file path
Returns
true if rotation is needed

Definition at line 29 of file log_rotation.cc.

◆ update_config()

void unilink::diagnostics::LogRotation::update_config ( const LogRotationConfig config)

Update rotation configuration.

Parameters
configNew configuration

Definition at line 109 of file log_rotation.cc.


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