I extended the python logger class given below:
class CommonLogger(Logger):
def debug(self, *args):
self.check_and_log(10, args)
def info(self, *args):
self.check_and_log(20, args)
def warn(self, *args):
self.check_and_log(30, args)
def error(self, *args):
self.check_and_log(40, args)
def check_and_log(self, level, args):
if self.isEnabledFor(level):
log_str = self.convert_list_to_string(args)
super().log(level, log_str)
@staticmethod
def convert_list_to_string(args):
return ''.join(str(msg) for msg in args)
And then create a logger in every class that uses it like so:
self.logger = CommonLogger(logging.getLogger(Constants.LOGGER_NAME))
self.logger.info('starting logger: ' + str(Constants.LOGGER_NAME))
But when I run this, it doesn't throw an error - but it also doesn't print any logs on console. Any idea why?
UPDATE: I compared this with the normal flow of a log getting printed - and it looks like my logging.handlers aren't initialized (empty list) inside Logger Class when its created as an implementation of the Logger Class.
handlers = {list} <class 'list'> []
while in a normal flow - handlers are filled out like so:
handlers = {list} <class 'list'>: [<StreamHandler <stdout> (INFO)>, <RotatingFileHandler D:\y\logs\engine.log (INFO)>]
0 = {StreamHandler} <StreamHandler <stdout> (INFO)>
1 = {RotatingFileHandler} <RotatingFileHandler D:\y\logs\engine.log (INFO)>
__len__ = {int} 2
Any Suggestions?