Skip to content

refactor: import the shared seismometer logger from core.logger - #199

Open
Sanilas-ai wants to merge 1 commit into
epic-open-source:mainfrom
Sanilas-ai:refactor/37-shared-logger
Open

Sanilas-ai wants to merge 1 commit into
epic-open-source:mainfrom
Sanilas-ai:refactor/37-shared-logger

Conversation

@Sanilas-ai

Copy link
Copy Markdown
Contributor

Overview

Closes #37

Description of changes

Most modules defined their own logger = logging.getLogger("seismometer"). This adds one module-level logger to seismometer.core.logger and has every module import it:

from seismometer.core.logger import logger
  • 21 modules now import the shared logger instead of building their own. import logging is dropped where nothing else used it.
  • 5 modules defined the logger but never logged (api/templates.py, controls/explore.py, controls/thresholds.py, plot/mpl/timeseries.py, table/fairness.py). I removed it there rather than add an unused import (flake8 F401).
  • seismometer.core.logger was already imported at package import time (through seismometer.api), so its logging.basicConfig() runs at the same point as before. The import adds no cycle: core/logger.py only imports the standard library.
  • seismometer.logger still exists and is the same object as before.
  • The three seismometer.telemetry loggers (core/autometrics.py, data/otel.py, data/telemetry.py) use a different name on purpose, so I left them alone. Happy to give them a shared accessor too if you'd like.

Verification

Python 3.12, in a clean venv with pip install -e ".[dev]":

  • pytest tests: 1552 passed, 1 skipped (1550 + the 2 new tests)
  • isort, black --line-length 119 and flake8 (versions from .pre-commit-config.yaml) clean on the changed files

Author Checklist

  • Linting passes; run early with pre-commit hook.
  • Tests added for new code and issue being fixed. (tests/core/test_logger.py: the shared logger is logging.getLogger("seismometer"), and modules use that same object)
  • Added type annotations and full numpy-style docstrings for new methods. (n/a, no new functions)
  • For breaking API changes, added .. versionchanged:: NEXT_VERSION_PLACEHOLDER directive to affected docstrings. (n/a, not a breaking change)
  • Draft your news fragment in new changelog/ISSUE.TYPE.rst files. (changelog/37.misc.rst)

Add a module-level logger to seismometer.core.logger and import it in
each module instead of calling logging.getLogger("seismometer") there.
Drop the logger from five modules that defined it but never logged.
The seismometer.telemetry loggers are unchanged.

Closes epic-open-source#37

Signed-off-by: Sanilas-ai <konstantinsanilas@gmail.com>
from seismometer.core.decorators import DiskCachedFunction

logger = logging.getLogger("seismometer")
from seismometer.core.logger import logger

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is not used here and you are making the change, can we just remove it?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Loggers should use a consistent API access pattern

2 participants