Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created June 17, 2020 04:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IndhumathyChelliah/3a8b36392ee8277f4b6e2246c7fbed03 to your computer and use it in GitHub Desktop.
Save IndhumathyChelliah/3a8b36392ee8277f4b6e2246c7fbed03 to your computer and use it in GitHub Desktop.
import logging
def getLog(nm):
#Creating custom logger
logger=logging.getLogger(nm)
#reading contents from properties file
f=open("properties.txt",'r')
if f.mode=="r":
loglevel=f.read()
if loglevel=="ERROR":
logger.setLevel(logging.ERROR)
elif loglevel=="DEBUG":
logger.setLevel(logging.DEBUG)
#Creating Formatters
formatter=logging.Formatter('%(asctime)s:%(levelname)s:%(name)s:%(message)s')
#Creating Handlers
file_handler=logging.FileHandler('test.log')
#Adding Formatters to Handlers
file_handler.setFormatter(formatter)
#Adding Handlers to logger
logger.addHandler(file_handler)
return logger
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment