Respect configured log level and make SQLAlchemy echo configurable (default off) - #258
Merged
Merged
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes task #2099.
Root cause
LoggingHandler.install()calledroot_logger.setLevel(logging.DEBUG), so every library logger (e.g. aiosqlite, ~10 lines/query) emitted DEBUG output.ConnectionFactory.create_engine()hard-codedecho=True, so every SQL statement was logged.Together these pushed downstream app logs to 0.5–2.5 GB/day.
Fix
LoggingConfiggainslevel(LOG_LEVEL, defaultinfo).LogProviderpasses it toLoggingManager→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).echo(DB_ECHO, defaultFalse, read lazily). The engine usescfg.get("echo", False).example/inertia-pingcrm-app/.env.exampledocumentsLOG_LEVELandDB_ECHO.LOG_LEVEL=debugto get the old behaviour back.echonow defaults to False. SetDB_ECHO=true(orecho=Truein the connection config) to log SQL again.Tests
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.--ignore=tests/masoniteorm/postgres): 2490 passed. ruff clean, basedpyright 0 errors, and every changed line is covered.🤖 Generated with Claude Code