Skip to content

Commit

Permalink
Removed the function configure_logging and added logging_config as ar…
Browse files Browse the repository at this point in the history
…gument to start_sandbox
  • Loading branch information
RINO-GAELICO committed Oct 15, 2024
1 parent e2a016a commit acdf5c0
Showing 1 changed file with 12 additions and 38 deletions.
50 changes: 12 additions & 38 deletions healthchain/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,43 +152,6 @@ def __init__(self) -> None:

return sandbox_decorator(service_config)

def configure_logging(logging_config=None):
"""
Configures logging based on the provided configuration. If no configuration is provided,
it defaults to a basic configuration with INFO level logging.
Parameters:
logging_config (dict, optional): A dictionary containing configurations for logging.
The dictionary should follow the structure defined in the Python logging configuration schema.
Returns:
None
Example:
configure_logging(logging_config={
"version": 1,
"formatters": {
"detailed": {
"class": "logging.Formatter",
"format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
}
},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"formatter": "detailed"
}
},
"root": {
"handlers": ["console"],
"level": "DEBUG",
},
})
"""
if logging_config:
logging.config.dictConfig(logging_config)
else:
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')

def sandbox_decorator(service_config: Optional[Dict] = None) -> Callable:
"""
Expand Down Expand Up @@ -248,12 +211,12 @@ def new_init(self, *args: Any, **kwargs: Any) -> None:
# Set the new init
cls.__init__ = new_init


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.
Expand All @@ -268,6 +231,17 @@ def start_sandbox(

self.sandbox_id = uuid.uuid4()

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",
)

log = logging.getLogger(__name__)

# Start service on thread
log.info(
f"Starting sandbox {self.sandbox_id} with {self.__class__.__name__} of type {self.type.value}..."
Expand Down

0 comments on commit acdf5c0

Please sign in to comment.