본문으로 건너뛰기
버전: 0.0.3

Logging

Built-in Rust-to-Python logging bridge that forwards all internal Rust logs to Python's logging module. Initialized automatically on import.

Quick Start

import logging
import aerospike_py

logging.basicConfig(level=logging.DEBUG)

client = aerospike_py.client({"hosts": [("127.0.0.1", 3000)]}).connect()
# DEBUG:aerospike_core::cluster: Connecting to seed 127.0.0.1:3000

Log Level Control

aerospike_py.set_log_level(aerospike_py.LOG_LEVEL_DEBUG)
ConstantValuePython Level
LOG_LEVEL_OFF-1(disabled)
LOG_LEVEL_ERROR0ERROR (40)
LOG_LEVEL_WARN1WARNING (30)
LOG_LEVEL_INFO2INFO (20)
LOG_LEVEL_DEBUG3DEBUG (10)
LOG_LEVEL_TRACE4TRACE (5)

Logger Names

LoggerDescription
aerospike_core::clusterCluster discovery, node management
aerospike_core::batchBatch operation execution
aerospike_core::commandIndividual command execution
aerospike_pyPython-side client wrapper
# Fine-grained control
logging.getLogger("aerospike_core::cluster").setLevel(logging.DEBUG)
logging.getLogger("aerospike_core::batch").setLevel(logging.WARNING)

JSON Logging

import logging, json

class JSONFormatter(logging.Formatter):
def format(self, record):
return json.dumps({
"timestamp": self.formatTime(record),
"level": record.levelname,
"logger": record.name,
"message": record.getMessage(),
})

handler = logging.StreamHandler()
handler.setFormatter(JSONFormatter())
logger = logging.getLogger("aerospike_core")
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)

Framework Integration

FastAPI

import logging
from contextlib import asynccontextmanager
import aerospike_py
from fastapi import FastAPI

logging.basicConfig(level=logging.INFO, format="%(asctime)s %(name)s %(levelname)s %(message)s")

@asynccontextmanager
async def lifespan(app: FastAPI):
aerospike_py.set_log_level(aerospike_py.LOG_LEVEL_INFO)
client = aerospike_py.AsyncClient({"hosts": [("127.0.0.1", 3000)]})
await client.connect()
app.state.aerospike = client
yield
await client.close()

app = FastAPI(lifespan=lifespan)

Django

# settings.py
LOGGING = {
"version": 1,
"handlers": {"console": {"class": "logging.StreamHandler"}},
"loggers": {
"aerospike_core": {"handlers": ["console"], "level": "INFO"},
"aerospike_py": {"handlers": ["console"], "level": "INFO"},
},
}

File Logging

import logging

handler = logging.FileHandler("aerospike.log")
handler.setFormatter(logging.Formatter("%(asctime)s %(levelname)s %(name)s %(message)s"))

for name in ["aerospike_core", "aerospike_py"]:
logger = logging.getLogger(name)
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)

Disabling

aerospike_py.set_log_level(aerospike_py.LOG_LEVEL_OFF)