Created
July 16, 2023 08:11
-
-
Save lyrick17/9103db10c2e36fda93c7657eb4ee33fc to your computer and use it in GitHub Desktop.
logging codes for Python, useful for debugging
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
| # This is set up code for logging in Python | |
| # - the format can be changed | |
| import logging | |
| logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s') | |
| # this is the set up instead if you want to save the logs in another file | |
| logging.basicConfig(filename="filename.txt", level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s') | |
| # Disable all the logs...(will be used to stop the logs) | |
| # - you can change CRITICAL into DEBUG, WARNING, INFO, ERROR, CRITICAL | |
| # depending on log level you want to disable | |
| # - where CRITICAL is highest log level | |
| logging.disable(logging.CRITICAL) | |
| # Comment this code if you don't want the logs to appear |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment