aitune.utils.logging
Logging configuration for the AITune package.
Module Contents
Classes
Functions
API
File-like object that writes to multiple destinations (tee functionality).
Return file descriptor of first file.
Flush all file objects.
Return whether this is an interactive stream.
Return whether object supports reading.
Return whether object supports writing.
Write data to all file objects.
Redirect all logging StreamHandlers to target file.
Parameters:
File object to redirect to
Original sys.stdout reference
Original sys.stderr reference
Returns:
List of (handler, original_stream) tuples for restoration
Redirect low-level file descriptors to target and return cleanup info.
Restore logging StreamHandlers to their original streams.
Parameters:
List of (handler, original_stream) tuples
Restore low-level file descriptors.
Try to redirect a single handler to target file.
Parameters:
The logging handler to redirect
File object to redirect to
Original sys.stdout reference
Original sys.stderr reference
Returns:
Tuple of (handler, original_stream) if successful, None otherwise
Silences or redirects stdout, stderr, and logs within the invoked context.
Parameters:
Optional file path to log output to
Suppress logging for all packages except the specified ones.
Parameters:
If False, libraries logs will be suppressed.
List of package names to exclude from suppression
Log a message with indentation.
Parameters:
Number of levels to indent
Arguments to pass to the sink function
Message to log
Function to use for logging
Log detailed exception information in a standardized format.
This function provides consistent and comprehensive exception logging across the AITune codebase, including exception type, message, and full traceback information.
Parameters:
Logger instance to use for logging
The exception that was caught
Custom error message describing the context
Logging level to use (default: ERROR)
Whether to re-raise the exception after logging (default: False)
Optional exception to raise instead of the original (default: None)
Raises:
Exception: Re-raises the original exception or the specified reraise_as exception
Append a message and optional exception details to a log file.
Set logging level for a specific module.
Parameters:
Name of the module (e.g., ‘aitune.torch.backend’)
Logging level (e.g., ‘DEBUG’, ‘INFO’, ‘WARNING’)
Configure logging for the AITune package.
This function sets up the root logger with appropriate handlers and formatting. Call this at the start of your application to ensure all logs are displayed.
Example usage: from aitune import setup_logging, set_module_level import logging
Configure with a log file and custom format
setup_logging( level=logging.DEBUG, format_string=”%(asctime)s - %(name)s - %(filename)s:%(lineno)d - %(levelname)s - %(message)s”, log_file=“aitune.log”, )
Set specific modules to different levels
set_module_level(“aitune.torch.backend.tensorrt”, logging.DEBUG) # Verbose TensorRT logs
Parameters:
Logging level (default: None, uses current root logger level)
Format for log messages
Optional file path to write logs to
If True, warnings will be captured and displayed
Write an exception traceback to a cache directory.