Skip to content

Logging Configuration

The cshelve module supports logging capabilities, enabling detailed logging for both the module itself and the underlying storage providers.

A custom logger can be passed directly to the cshelve.open function using the logger parameter, allowing greater control over logging behavior.

import logging
import cshelve
custom_logger = logging.getLogger('custom_cshelve_logger')
custom_logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler()
custom_logger.addHandler(handler)
with cshelve.open('config.ini', logger=custom_logger) as db:
...

Some storage providers offer their own detailed logging capabilities. Provider-specific logging settings can be enabled in the configuration file.

Configuration file:

[default]
provider = azure-blob
account_url = https://myaccount.blob.core.windows.net
auth_type = passwordless
container_name = mycontainer
[logging]
http = true
credentials = true

Python usage:

import logging
import sys
import cshelve
# Configure Azure-specific logging
logger = logging.getLogger('azure')
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler(sys.stdout)
logger.addHandler(handler)
with cshelve.open('azure-blob.ini') as db:
...

For detailed logging capabilities, refer to the documentation of your specific cloud storage provider.