AttributeError: Logger instance has no attribute 'setFormatter'

J

johnny

I am getting a log error. I am running ActiveState Python 2.4.3. Any
help greatly appreciated. Here is my code:

file.py
---------

def main()
setupLogging()
blah....

def setupLogging():
global log
log = logging.getLogger("ftp")
formatter = logging.Formatter('%(name)-12s: %(levelname)-8s
%(message)s')

log.setFormatter(formatter)
log.setLevel(logging.DEBUG)

fhnd = logging.FileHandler('py_mybase.log')
fhnd.setLevel(logging.DEBUG)
log.addHandler(fhnd)

My Error:
log.setFormatter(formatter)
AttributeError: Logger instance has no attribute 'setFormatter'
 
G

Gabriel Genellina

def setupLogging():
global log
log = logging.getLogger("ftp")
formatter = logging.Formatter('%(name)-12s: %(levelname)-8s
%(message)s')

log.setFormatter(formatter)
log.setLevel(logging.DEBUG)

fhnd = logging.FileHandler('py_mybase.log')
fhnd.setLevel(logging.DEBUG)
log.addHandler(fhnd)

My Error:
log.setFormatter(formatter)
AttributeError: Logger instance has no attribute 'setFormatter'

If you look for setFormatter in the Python docs, you find that it is
an attribute of Handler instances. So, move it down to fhnd.setFormatter(...)


--
Gabriel Genellina
Softlab SRL

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
 
G

Gabriel Genellina

At Monday 11/12/2006 22:32, johnny wrote:

def setupLogging():
global log
log = logging.getLogger("ftp")

Also, there is no need to use a global here. The logging machinery
will return always the same logger given the same name. So
logging.getLogger("ftp") will be always the same.


--
Gabriel Genellina
Softlab SRL

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top