Skip to content

Respect configured log level and make SQLAlchemy echo configurable (default off) - #258

Merged
tmgbedu merged 1 commit into
mainfrom
task/log-level-db-echo
Sep 27, 2026
Merged

tmgbedu merged 1 commit into
mainfrom
task/log-level-db-echo

Conversation

@tmgbedu

@tmgbedu tmgbedu commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

Closes task #2099.

Root cause

  • LoggingHandler.install() called root_logger.setLevel(logging.DEBUG), so every library logger (e.g. aiosqlite, ~10 lines/query) emitted DEBUG output.
  • ConnectionFactory.create_engine() hard-coded echo=True, so every SQL statement was logged.

Together these pushed downstream app logs to 0.5–2.5 GB/day.

Fix

  • LoggingConfig gains level (LOG_LEVEL, default info). LogProvider passes it to LoggingManager → LoggingHandler.install(level), which applies only the configured level. It never forces DEBUG, and with no level it leaves the root logger alone. Framework-only levels map to stdlib ones (notice→INFO, alert/emergency→CRITICAL).
  • SQLite/MySQL/Postgres connection configs gain echo (DB_ECHO, default False, read lazily). The engine uses cfg.get("echo", False).
  • example/inertia-pingcrm-app/.env.example documents LOG_LEVEL and DB_ECHO.
  • Log drivers and FileHandler code are untouched (sibling task #2098).

⚠️ Behaviour change: less log output by default

  • The default effective root log level changes from DEBUG to INFO. Set LOG_LEVEL=debug to get the old behaviour back.
  • SQLAlchemy echo now defaults to False. Set DB_ECHO=true (or echo=True in the connection config) to log SQL again.

Tests

  • New tests/logging/test_log_level.py: INFO leaves root at INFO; no level leaves root untouched; the level is re-applied when the handler is already installed; level mapping; config default.
  • tests/masoniteorm/config/test_db_url.py: engine echo is False by default and True when configured; all connection configs default echo to False.
  • Full suite (--ignore=tests/masoniteorm/postgres): 2490 passed. ruff clean, basedpyright 0 errors, and every changed line is covered.

🤖 Generated with Claude Code

LoggingHandler.install() forced the root logger to DEBUG, and the ORM engine
hard-coded echo=True, flooding logs with SQL and aiosqlite debug output.
The root level now follows logging.level (LOG_LEVEL, default info) and the
engine echo follows the connection's echo option (DB_ECHO, default false).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Sep 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@tmgbedu
tmgbedu merged commit eac4452 into main Sep 27, 2026
6 checks passed
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.

1 participant