[Tutor] "alias" instance of logger

Robert Jackson wolf1boy85 at yahoo.com
Sat Oct 6 04:23:28 CEST 2007

By the way, I could have SWORN that I've done this successfully in the past in another program.  I am relatively certain I have used log.LEVEL() in some of my programs in the past, but I can't figure out how I did it.


----- Original Message ----
From: Robert Jackson <wolf1boy85 at yahoo.com>
To: tutor at python.org
Sent: Friday, October 5, 2007 10:22:26 PM
Subject: "alias" instance of logger

I'm working with an instance of a Python logger.

Some code:

log = logging.basicConfig(level=logging.DEBUG,filename="/home/richard/templog",filemode='w')

Later in my program I do:

log.info("finished step 4.")

Python spits out this error:

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

AttributeError: 'NoneType' object has no attribute 'info'

I CAN, however, do:
logging.info("finished step 4.")

And it works.

What confuses me about this is that I can do something like this:

# call another function and pass it the logger instance:


And, if I define foo() like this:

def foo(log):

   # this works fine!

   log.info("finished step 4.")

The log.info works fine inside of foo().

Why is it that I can pass logging as an instance into a function, and
use whatever instance name I wants inside of foo(), but I can't assign
an "alias" for the logging instance inside of main() (by doing instancealias = logging.basic())?


Boardwalk for $500? In 2007? Ha! Play Monopoly Here and Now (it's updated for today's economy) at Yahoo! Games.

Take the Internet to Go: Yahoo!Go puts the Internet in your pocket: mail, news, photos & more. 

More information about the Tutor mailing list