Skip to content

Add sandbox configuration #32

Closed
@jenniferjiangkells

Description

@jenniferjiangkells

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

  1. Add a logging_config parameter to the start_sandbox function.
  2. Use Python's logging.config module to apply the configuration.
  3. 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

No one assigned

    Labels

    Component: LoggingIssue/PR that addresses logging functionalitygood first issueGood for newcomershacktoberfestIssues suitable for hacktoberfest

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions