Skip to content

Commit

Permalink
fix sqlalchemy logging, echo uses own logger
Browse files Browse the repository at this point in the history
  • Loading branch information
fpletz committed Sep 26, 2023
1 parent 0c5d655 commit aae52c5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 36 deletions.
35 changes: 0 additions & 35 deletions alembic.ini
Original file line number Diff line number Diff line change
Expand Up @@ -77,38 +77,3 @@ output_encoding = utf-8
# ruff.type = exec
# ruff.executable = %(here)s/.venv/bin/ruff
# ruff.options = --fix REVISION_SCRIPT_FILENAME

# Logging configuration
[loggers]
keys = root,sqlalchemy,alembic

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = WARN
handlers = console
qualname =

[logger_sqlalchemy]
level = WARN
handlers =
qualname = sqlalchemy.engine

[logger_alembic]
level = INFO
handlers =
qualname = alembic

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(levelname)-5.5s [%(name)s] %(message)s
datefmt = %H:%M:%S
3 changes: 2 additions & 1 deletion atciss/app/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ def get_application() -> FastAPI:
on_shutdown=[on_shutdown],
)

app.add_middleware(CorrelationIdMiddleware)

_ = PrometheusInstrumentator().instrument(app).expose(app, tags=["monitoring"])

app.add_middleware(
SQLAlchemyMiddleware,
db_url=str(settings.DATABASE_DSN),
engine_args={ # engine arguments example
"echo": True,
"pool_pre_ping": True,
"pool_size": 5,
"max_overflow": 10,
Expand Down
6 changes: 6 additions & 0 deletions atciss/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ def setup_logging() -> None:
)

logging.basicConfig(handlers=[InterceptHandler()], level=0)

# sqlalchemy prints queries on info level when we have DEBUG enabled
logging.getLogger("sqlalchemy.engine").setLevel(
logging.INFO if settings.DEBUG else logging.WARN
)

for name in logging.root.manager.loggerDict.keys():
_logger = logging.getLogger(name)
_logger.handlers = [InterceptHandler()]
Expand Down

0 comments on commit aae52c5

Please sign in to comment.