Closed
Description
Description
Implement configurable logging in the start_sandbox
function of the sandbox decorator. Currently, the logging is hardcoded, which limits flexibility for users who may want to adjust log levels or output formats based on their specific needs.
Context
The start_sandbox
function initialises the service and sends requests through the client. Having configurable logging for this function would allow users to:
- Adjust log levels (e.g., DEBUG, INFO, WARNING) based on their debugging needs
- Customise log formats to include or exclude certain information
- Direct logs to different outputs (console, file, etc.)
This enhancement would improve the usability and flexibility of our sandbox environment, especially for users who are debugging or integrating our tool into their workflows.
Possible Implementation
- Add a
logging_config
parameter to thestart_sandbox
function. - Use Python's
logging.config
module to apply the configuration. - Provide sensible defaults for users who don't specify a logging configuration.
import logging.config
def start_sandbox(
self,
service_id: str = "1",
save_data: bool = True,
save_dir: str = "./output/",
logging_config: Optional[Dict] = None,
) -> None:
"""
Starts the sandbox: initialises service and sends a request through the client.
Args:
service_id (str): The ID of the service to start. Defaults to "1".
save_data (bool): Whether to save request and response data. Defaults to True.
save_dir (str): Directory to save data in. Defaults to "./output/".
logging_config (Optional[Dict]): Configuration for logging. If None, uses default config.
"""
if logging_config:
logging.config.dictConfig(logging_config)
else:
# Set up default logging configuration
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
# ... rest of the function ...
Possible Alternatives
- Use environment variables for logging configuration instead of function parameters.
- Implement a global logging configuration for the entire package, which the start_sandbox function would use.
- Create a separate configure_logging function that users can call before start_sandbox.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Done