I'm trying to create a custom logger this way:
File: logger.py
import logging
class Logger(logging.getLoggerClass()):
def warning(self, msg, *args, **kwargs):
super(Logger, self).warning(msg, *args, **kwargs)
logging.setLoggerClass(Logger)
log = logging.getLogger('test')
handler = logging.StreamHandler()
formatter = logging.Formatter('%(pathname)s')
handler.setFormatter(formatter)
log.addHandler(handler)
File: test.py
from logger import log
log.warning('')
Output:
$ python test.py
/home/dario/Desktop/logging_test/logger.py
The expected output would be:
/home/dario/Desktop/logging_test/test.py
What's even weirder, if I comment the setLoggerClass
line I do get test.py
, but without the full path.
What am I doing wrong? Thank you!
Tested with Python 2.7.4 and 3.3.1 on Arch Linux x86_64.