Created
June 7, 2019 16:03
-
-
Save isaacgr/ad0380ba58df579d51ae81859db64223 to your computer and use it in GitHub Desktop.
Setup logging for python scripts
This file contains 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 | |
FORMAT = "%(asctime)s:%(levelname)s:%(name)s:%(message)s" | |
datefmt = "%Y-%m-%d-%H:%M:%S" | |
log = logging.getLogger(__name__) | |
logging.basicConfig(filename="output.log", level=logging.INFO, | |
format=FORMAT, datefmt=datefmt) | |
def log_test(): | |
log.info('Info') | |
log.warning('Warning') | |
log.critical('Critical') | |
if __name__ == '__main__': | |
log_test() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment