6

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'
1

1 Answer 1

15

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.