Skip to content

Instantly share code, notes, and snippets.

@marcelopalin
Created January 24, 2022 13:42
Show Gist options
  • Select an option

  • Save marcelopalin/29d0413b1f7147d7effb9cc9f8b88bbf to your computer and use it in GitHub Desktop.

Select an option

Save marcelopalin/29d0413b1f7147d7effb9cc9f8b88bbf to your computer and use it in GitHub Desktop.
"""
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