-
-
Save ciel334288/3c68f30b1ed674bdf7e5045922d23178 to your computer and use it in GitHub Desktop.
python 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 os,\ | |
| logging | |
| logger = logging.getLogger(__name__) | |
| logger.setLevel(logging.ERROR) | |
| LOGS = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'logs') | |
| filehandler = logging.FileHandler(os.path.join(LOGS, 'main.log'), mode='a') | |
| formatter = logging.Formatter('%(asctime)s : %(name)s : %(message)s') | |
| logger.addHandler(filehandler) | |
| filehandler.setFormatter(formatter) | |
| logger.info("Exception!!!") # std console output | |
| logger.error("Exception!!!") # std console output and log file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment