Logger Methods
Synchronous loggers come from get_logger() and expose synchronous methods. Async loggers come from get_async_logger() / runtime_async() and their logging methods are awaitable.
debug {#debug}
# Sync
logger.debug(message: str, *, exc: BaseException | None = None, exc_info: Any | None = None, **metadata) -> None
# Async
await logger.debug(message: str, *, exc: BaseException | None = None, exc_info: Any | None = None, **metadata) -> None
Log diagnostic information.
Example
# sync
logger.debug("Processing user", user_id="123", stage="preflight")
# async
await async_logger.debug("Processing user", user_id="123", stage="preflight")
info {#info}
logger.info(message: str, *, exc: BaseException | None = None, exc_info: Any | None = None, **metadata) -> None
await async_logger.info(message: str, *, exc: BaseException | None = None, exc_info: Any | None = None, **metadata) -> None
Log application or business events.
Example
logger.info("User logged in", user_id="abc-123", ip="192.168.1.100")
await async_logger.info("Job completed", job_id="job-42", duration_ms=87)
warning {#warning}
logger.warning(message: str, *, exc: BaseException | None = None, exc_info: Any | None = None, **metadata) -> None
await async_logger.warning(message: str, *, exc: BaseException | None = None, exc_info: Any | None = None, **metadata) -> None
Log potentially problematic situations.
Example
logger.warning("Slow dependency", dependency="postgres", latency_ms=1200)
error {#error}
logger.error(message: str, *, exc: BaseException | None = None, exc_info: Any | None = None, **metadata) -> None
await async_logger.error(message: str, *, exc: BaseException | None = None, exc_info: Any | None = None, **metadata) -> None
Log errors. Pass exc_info=True to include the current exception or exc=<exception> to serialize a specific one.
Example
try:
do_work()
except Exception:
logger.error("Work failed", exc_info=True)
critical {#critical}
logger.critical(message: str, *, exc: BaseException | None = None, exc_info: Any | None = None, **metadata) -> None
await async_logger.critical(message: str, *, exc: BaseException | None = None, exc_info: Any | None = None, **metadata) -> None
Log critical errors. CRITICAL indicates a severe error that may cause the application to abort. Use for unrecoverable failures requiring immediate attention.
Example
logger.critical("Database connection lost", db_host="prod-db", retry_count=3)
await async_logger.critical("System failure", component="auth", error_code="AUTH_001")
exception {#exception}
logger.exception(message: str = "", **metadata) -> None
await async_logger.exception(message: str = "", **metadata) -> None
Convenience for error(..., exc_info=True) inside an exception handler.
Example
try:
await process()
except Exception:
await async_logger.exception("Process crashed", request_id="req-1")
Context binding
logger.bind(**context) -> Logger
logger.unbind(*keys) -> Logger
logger.clear_context() -> None
Context is stored per task/thread and merged into every log call until cleared.
Example
logger.bind(request_id="req-123", user_id="user-7")
logger.info("Request started")
logger.unbind("user_id")
logger.info("Still has request_id")
logger.clear_context()
Async-only lifecycle helpers
await async_logger.drain() # graceful shutdown; returns DrainResult
Sync loggers expose stop_and_drain() as an async method. Use asyncio.run(logger.stop_and_drain()) if you need to stop outside of runtime().
These methods cover the supported public surface for both sync and async loggers.