Skip to content

Centralize logger configuration and adopt structured logging #855

@shiwani42

Description

@shiwani42

Issue

What is the issue?

Every module in the application independently calls logging.basicConfig() with no arguments and hardcodes logger.setLevel(logging.INFO). There are 25 such occurrences across the codebase.

This pattern has two concrete problems:

  1. logging.basicConfig() is a no-op after the first call. Whichever module happens to be imported first claims the root logger; every subsequent call is silently ignored. Log format and handler behaviour are therefore undefined for most of the application.
  2. There is no way to change the log level or output format at runtime without editing source files.

There is also no structured (machine-readable) log output, which makes it difficult to aggregate or query logs in production or CI environments.

Expected Behaviour

Logger configuration should be centralised in one place. The log level and format should be controllable via environment variables (LOG_LEVEL, LOG_FORMAT) without any code changes. Setting LOG_FORMAT=json should produce one JSON object per line, suitable for log aggregation tools.

Actual Behaviour

25 modules each call logging.basicConfig() with no arguments. Only the first call has any effect. All modules hardcode INFO level. No structured output is available.

grep -rn "logging.basicConfig" application/ --include="*.py" | wc -l
# 25

Steps to reproduce

  1. Import any two application modules that both call logging.basicConfig().
  2. Observe that log format is whatever Python's default is, with no way to override it at runtime.
  3. Note that changing LOG_LEVEL or LOG_FORMAT environment variables has no effect.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions