Skip to content

log-get-logger (BTLOG001)

Added in 0.8.0 · Stable · Enabled by default (warning)

Family: logging · Standard: CES-45 · Languages: python

Directive

Never call logging.getLogger(...), or a bare getLogger(...), directly. Get loggers from the house get_logger of core/logger.py, the structlog setup that botica refs show structured-logging prints. A warning by default.

Why

  • One configuration point makes every module log the same way: JSON in production, a coloured console in development, the level from LOG_LEVEL. Scattered getLogger calls drift into inconsistent formats and lost context.
  • get_logger returns a structlog BoundLogger, so you can .bind(request_id=...) context and emit key/value events instead of pre-formatted strings.

Do

from myapp.core.logger import get_logger

log = get_logger(__name__)
log.info("user_created", user_id=user.id)

Don't

import logging

log = logging.getLogger(__name__)

Suppression

A comment on the line of the getLogger(...) call silences it.

log = logging.getLogger(__name__)  # botica: ignore[log-get-logger]
log = logging.getLogger(__name__)  # noqa: BTLOG001 -- reason

References

Discussion