Skip to content

Instantly share code, notes, and snippets.

@Harshakvarma
Created June 20, 2018 05:14
Show Gist options
  • Save Harshakvarma/236131a90081b23356eee5f2d4535c9a to your computer and use it in GitHub Desktop.
Save Harshakvarma/236131a90081b23356eee5f2d4535c9a to your computer and use it in GitHub Desktop.
Python sample loop to test background running
import os
import time
import logging
from datetime import datetime
#logs
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
# create a file handler
# logPath = os.path.join('logs/'+datetime.now().strftime('main_facebook_posts_%H_%M_%d_%m_%Y.log'))
logPath = os.path.join('./testing.log')
print("logPath ="+logPath)
handler = logging.FileHandler(logPath)
handler.setLevel(logging.INFO)
# create a logging format
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
# add the handlers to the logger
logger.addHandler(handler)
for x in range(0, 100000):
print ("We're on time %d" % (x))
logger.info("We're on time %d" % (x))
time.sleep(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment