Created
January 24, 2022 13:42
-
-
Save marcelopalin/29d0413b1f7147d7effb9cc9f8b88bbf to your computer and use it in GitHub Desktop.
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
| """ | |
| program.py | |
| This script will keep adding logs to our logger file. | |
| """ | |
| import logging | |
| import time | |
| import os | |
| # create logger with log app | |
| real_path = os.path.realpath(__file__) | |
| dir_path = os.path.dirname(real_path) | |
| LOGFILE = f"app/logs/log_gerado.log" | |
| logger = logging.getLogger('log_app') | |
| logger.setLevel(logging.DEBUG) | |
| fh = logging.FileHandler(LOGFILE) | |
| formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') | |
| fh.setFormatter(formatter) | |
| logger.addHandler(fh) | |
| #infinite while loop printing to our log file. | |
| i = 0 | |
| while True: | |
| logger.info(f"log message num: {i}") | |
| i += 1 | |
| time.sleep(0.3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment