Skip to content

Commit

Permalink
documented logging
Browse files Browse the repository at this point in the history
  • Loading branch information
dmalan committed Jun 7, 2022
1 parent 6e31363 commit 866aafc
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions libraries/cs50/python.rst
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,30 @@ Parameter markers (e.g., ``?``) can only be used as placeholders for "literals"
if column in ["foo", "bar", "baz"]:
rows = db.execute(f"SELECT * FROM {column}")
How can I enable logging of SQL statements?
-------------------------------------------

By default, logging of SQL statements is disabled unless you have an environment variable called ``FLASK_ENV``, the value of which is ``development``, as is the case in `Visual Studio Code for CS50 <https://cs50.readthedocs.io/code/>`_. You can enable logging of SQL statements with code like:

.. code-block::
import logging
logging.getLogger("cs50").disabled = False
Statements that succeed will be prefixed with ``INFO``. Statements that fail will be prefixed with ``ERROR``.

How can I disable logging of SQL statements?
--------------------------------------------

To disable logging of SQL statements, even if you have an environment variable called ``FLASK_ENV``, the value of which is ``development``, as is the case in `Visual Studio Code for CS50 <https://cs50.readthedocs.io/code/>`_, you can use code like:

.. code-block::
import logging
logging.getLogger("cs50").setLevel("CRITICAL")
Troubleshooting
===============

Expand Down

0 comments on commit 866aafc

Please sign in to comment.