Last active
December 2, 2022 02:15
-
-
Save davidas13/ca8d303522c0fac57328e53a85f2013d to your computer and use it in GitHub Desktop.
Python Logging #logging
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
| import logging | |
| import sys | |
| root = logging.getLogger() | |
| root.setLevel(logging.DEBUG) | |
| handler = logging.StreamHandler(sys.stdout) | |
| handler.setLevel(logging.DEBUG) | |
| formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') | |
| handler.setFormatter(formatter) | |
| root.addHandler(handler) |
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
| import logging | |
| import sys | |
| file_handler = logging.FileHandler(filename='tmp.log') | |
| stdout_handler = logging.StreamHandler(stream=sys.stdout) | |
| handlers = [file_handler, stdout_handler] | |
| logging.basicConfig( | |
| level=logging.DEBUG, | |
| format='[%(asctime)s] {%(filename)s:%(lineno)d} %(levelname)s - %(message)s', | |
| handlers=handlers | |
| ) | |
| logger = logging.getLogger('LOGGER_NAME') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment