-
-
Save IndhumathyChelliah/3a8b36392ee8277f4b6e2246c7fbed03 to your computer and use it in GitHub Desktop.
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 | |
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