Coverage for /home/martinb/.local/share/virtualenvs/camcops/lib/python3.6/site-packages/cardinal_pythonlib/sqlalchemy/logs.py : 100%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1#!/usr/bin/env python
2# cardinal_pythonlib/sqlalchemy/logs.py
4"""
5===============================================================================
7 Original code copyright (C) 2009-2021 Rudolf Cardinal (rudolf@pobox.com).
9 This file is part of cardinal_pythonlib.
11 Licensed under the Apache License, Version 2.0 (the "License");
12 you may not use this file except in compliance with the License.
13 You may obtain a copy of the License at
15 https://www.apache.org/licenses/LICENSE-2.0
17 Unless required by applicable law or agreed to in writing, software
18 distributed under the License is distributed on an "AS IS" BASIS,
19 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 See the License for the specific language governing permissions and
21 limitations under the License.
23===============================================================================
25**Functions to assist with SQLAlchemy logs.**
27"""
29import logging
32def pre_disable_sqlalchemy_extra_echo_log() -> None:
33 """
34 Adds a null handler to the log named ``sqlalchemy.engine.base.Engine``,
35 which prevents a duplicated log stream being created later.
37 Why is this necessary?
39 If you create an SQLAlchemy :class:`Engine` with ``echo=True``, it creates
40 an additional log to ``stdout``, via
42 .. code-block:: python
44 sqlalchemy.engine.base.Engine.__init__()
45 sqlalchemy.log.instance_logger()
46 sqlalchemy.log.InstanceLogger.__init__()
47 # ... which checks that the logger has no handlers and if not calls:
48 sqlalchemy.log._add_default_handler()
49 # ... which adds a handler to sys.stdout
50 """
51 log = logging.getLogger("sqlalchemy.engine.base.Engine")
52 log.addHandler(logging.NullHandler())