Skip to content Skip to sidebar Skip to footer

Python Logging Module Having A Formatter Causes Attributeerror

I am writing a terminal application, which, after passing in -v option, gets, unsurprisingly, verbose. I want to have the output available in the terminal, for easy testing (it get

Solution 1:

Instead of

handler = logging.StreamHandler(stdout).setFormatter(formatter)

Try:

handler = logging.StreamHandler(stdout)
handler.setFormatter(formatter)

What is happening is that in the first case you are assigning the return of setFormatter() to the handler variable, but setFormatter() does not return the handler (i.e. it returns None)

Post a Comment for "Python Logging Module Having A Formatter Causes Attributeerror"