473,396 Members | 1,894 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

AttributeError: Logger instance has no attribute 'setFormatter'

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'

Dec 12 '06 #1
2 5351
At Monday 11/12/2006 22:32, johnny wrote:
>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
Dec 12 '06 #2
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
Dec 12 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Nermin Brgulja | last post by:
Hi, I am using jdk1.4 Logger with a FileHandler for logging in a web application, and have two questions regarding logging: The first question is: I've created an Logger and mapped it to an...
0
by: seth | last post by:
Last week I encountered an AttributeError in my unit tests that I wasn'table to catch with an "except AttributeError" statement. The problem stemmed from a class that raised an error inside...
0
by: Erlend Fuglum | last post by:
I have tried and tried, but cannot figure out the source of the following error: AttributeError: 'module' object has no attribute 'menyHMTL' __doc__ = 'Attribute not found.' __getitem__ =...
3
by: MackS | last post by:
I'm new to Python. In general I manage to understand what is happening when things go wrong. However, the small program I am writing now fails with the following message: AttributeError: ClassA...
1
by: peiyin.li | last post by:
Hi, I want to have two loggers that logs to two different files. Here is what I have: import logging import logging.handlers project1Handler = logging.handlers.RotatingFileHandler(...
5
by: CedricCicada | last post by:
Greetings! I want to write messages into the Windows event log. I found sevicemanager, but the source is always "Python Service", and I'd like to be a bit more descriptive. Poking around on...
4
by: garyjefferson123 | last post by:
Suppose I have some sort of context variable that I want to appear in log messages. E.g.: logger = logging.getLogger("somelogger") class SomeOp: def __init__(self, ctx): self.ctx = ctx def...
2
by: DwBear75 | last post by:
I am hoping to find some simple examples of how to create a logger instance using smtphandler. I don't want to create a separate ini file. I just want to sent the smtphost, from, to right in the...
4
by: skunkwerk | last post by:
i'm redirecting the stdout & stderr of my python program to a log. Tests i've done on a simple program with print statements, etc. work fine. however, in my actual program i get weird output like...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.