I am new to Python and trying to implement logger in my code. I have created a python file: setup_logger.py
import logging
CLASS_NAME = ''
# Create and configure logger
LOG_FORMAT = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
logging.basicConfig(filename='/Users/bobby/Desktop/lumberjack.log', level=logging.DEBUG, format=LOG_FORMAT)
logger = logging.getLogger()
I am using this logger configuration in another python file: GetLogger.py as below
from LoggerLevels.setup_logger import logger
if __name__ == '__main__':
logger.error('This is a basic log error message')
logger.info('This is a warning message')
The log is being printed in the file as:
2020-06-17 14:54:47,161 - root - ERROR - This is a basic log error message
2020-06-17 14:54:47,161 - root - INFO - This is a warning message
But I see the class name is printed as root. I understand that it is coming due to the setting in setup_logger.py file.
Is there anyway I can send the current class name that is logging messages into my file ?
For ex:
I am using the logger object from GetLogger.py file. Is there anyway I can log the message as
2020-06-17 14:54:47,161 - GetLogger - ERROR - This is a basic log error message
2020-06-17 14:54:47,161 - GetLogger - INFO - This is a warning message
Could anyone let me know how can I achieve that ?