I tried to implement a logger into my python script according to the python documentation. This is the code:
import logging
def generateLogger(loggername='SM-Logger', path="logs/log.log"):
logger = logging.getLogger(loggername)
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.ERROR)
formatter = logging.Formatter('%(asctime)s - %(name)s\
- %(levelname)s - %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)
return logger
logger = generateLogger("testlogger", "testlog.log")
logger.WARNING("testtest")
I get this error message:
File "loggertest.py", line 39, in <module>
logger.WARNING("testtest")
AttributeError: 'Logger' object has no attribute ‚WARNING'
The solution is to change the last line
logger.WARNING("testtest")
into
logger.warning("testtest")
Lower-case "warning" is the function, upper-case "WARNING" is the variable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With