I am trying to get my head around how to use the Logging module in Python.
I have the below main code :
import logging
import First
logging.basicConfig(level=logging.DEBUG,format='%(asctime)s %(levelname)s %(message)s',filename=r'C:\Users\bhatsubh\Desktop\Everything\Codes\Python\Logs\automation.log',filemode='a')
logging.debug('A debug message')
logging.info('Some information')
logging.warning('A shot across the bows')
logging.error('Committed a blunder')
obj = First.Demo("Subhayan",75000)
print (obj.getSal())
The First.py module contains the below code:
class Demo:
def __init__(self,Name,salary):
logging.info("Inside Demo init")
self.name = Name
self.salary = salary
def getSal(self):
logging.info("Inside Demo getSal")
sal = self.salary * 100
return sal
Now is there someway in which i can import the module logging at the top level of my module file and then use it in the rest of the calls without importing it again in every other file.?
Thanks a lot in advance for any explanations.