Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: 'Logger' object has no attribute ‚WARNING'

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'
like image 894
felice Avatar asked Dec 23 '22 17:12

felice


1 Answers

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.

like image 108
felice Avatar answered Dec 30 '22 10:12

felice