Trailer Finder is a tool that automatically searches and downloads movie trailers for your media collection. It integrates with media management tools like Radarr and Sonarr to keep your trailers up-to-date.
MIT License
15
stars
0
forks
source link
Enhancements to Logging Module: Parameter Validation, Exception Handling, and Performance Optimization #35
Overall Objective:
We have reviewed and enhanced the logging module to optimize its performance, improve robustness, and ensure better system resource management while preserving the functionality of color-coded logging and file rotation support.
1. Constructor Argument Validation:
Checking log_max_size and log_backup_count Parameters:
We added validation to ensure that log_max_size and log_backup_count arguments are positive integers. This prevents unexpected errors if incorrect values are provided during logger initialization.
Validation of Logging Level (log_level):
Validation is performed to ensure that the provided logging level (log_level) is among the accepted levels (DEBUG, INFO, WARNING, ERROR, CRITICAL). This guarantees that the logging level is valid and prevents configuration errors.
2. Exception Handling for File Handler:
try-except Block for File Handler Setup:
We wrapped the file handler setup in a try-except block to capture and report any errors that might occur while creating the log directory or initializing the file handler. Errors are now printed to the standard error output, making it easier to debug and identify issues related to log file configuration.
3. CPU Load Management with Pause:
Maintaining sleep(1) in _log:
The 1-second pause in the _log method is maintained to avoid excessive CPU load during resource-intensive operations such as those involving ffmpeg or ffprobe. This pause helps regulate CPU usage and ensures that the system remains responsive even under heavy logging conditions.
4. General Improvements:
Comments and Documentation:
The documentation has been updated to reflect the changes and provide a clear description of the attributes and methods of the Logger class. This enhances understanding of the module and facilitates its use.
Type Hints:
Type annotations have been added to method parameters and return values, improving code readability and assisting static analysis tools in type consistency checks.
Overall Objective: We have reviewed and enhanced the logging module to optimize its performance, improve robustness, and ensure better system resource management while preserving the functionality of color-coded logging and file rotation support.
1. Constructor Argument Validation:
log_max_size
andlog_backup_count
Parameters: We added validation to ensure thatlog_max_size
andlog_backup_count
arguments are positive integers. This prevents unexpected errors if incorrect values are provided during logger initialization.log_level
): Validation is performed to ensure that the provided logging level (log_level
) is among the accepted levels (DEBUG, INFO, WARNING, ERROR, CRITICAL). This guarantees that the logging level is valid and prevents configuration errors.2. Exception Handling for File Handler:
try-except
Block for File Handler Setup: We wrapped the file handler setup in atry-except
block to capture and report any errors that might occur while creating the log directory or initializing the file handler. Errors are now printed to the standard error output, making it easier to debug and identify issues related to log file configuration.3. CPU Load Management with Pause:
sleep(1)
in_log
: The 1-second pause in the_log
method is maintained to avoid excessive CPU load during resource-intensive operations such as those involvingffmpeg
orffprobe
. This pause helps regulate CPU usage and ensures that the system remains responsive even under heavy logging conditions.4. General Improvements:
Logger
class. This enhances understanding of the module and facilitates its use.