Logging

K

Kamus of Kadizhar

Does anyone have a working example or a recipe of a simple logging
system using the logging module? Any FM I can refer to?

I can't seem to get it right - I can't even make sense of the standard
library docs. What do I have to do to log records to a file?

(Newbie Q, as you might guess...)

-Kamus
 
J

John Abel

Try this. It records anything Warning and above.

logFacility = logging.getLogger( "MyApp" )
logFile = logging.FileHandler( "LogFile.log" )
logFormat = logging.Formatter( '%(asctime)s %(levelname)s
%(message)s' )
logFile.setFormatter( logFormat )
logFacility.addHandler( logFile )
logFacility.setLevel( logging.WARNING )

logFacility.info( "Starting Up" )
**

HTH

John
 
A

Anthony Baxter

Does anyone have a working example or a recipe of a simple logging
system using the logging module? Any FM I can refer to?

I can't seem to get it right - I can't even make sense of the standard
library docs. What do I have to do to log records to a file?

Did you look in the logging documentation? At the end of the
current docs, there's a simple example:

http://www.python.org/dev/doc/devel/lib/node302.html
 
K

Kamus of Kadizhar

Did you look in the logging documentation? At the end of the
current docs, there's a simple example:

Missed that.

Is there a search on python.org that only searches docs? That would be
really helpful.... I keep coming up with gobs of irrelevant stuff on my
searches.

I keep missing simple stuff like that.

-Kamus
 
G

Gerrit Holl

Kamus said:
Missed that.
Is there a search on python.org that only searches docs? That would be
really helpful.... I keep coming up with gobs of irrelevant stuff on my
searches.

I keep missing simple stuff like that.

Not really a search engine, but the index of the documentation can be
very useful. Also very useful is simply browsing the documentation
without looking for something specific, just to get the feeling what it
is there is.

Gerrit.

--
49. If any one take money from a merchant, and give the merchant a
field tillable for corn or sesame and order him to plant corn or sesame in
the field, and to harvest the crop; if the cultivator plant corn or sesame
in the field, at the harvest the corn or sesame that is in the field shall
belong to the owner of the field and he shall pay corn as rent, for the
money he received from the merchant, and the livelihood of the cultivator
shall he give to the merchant.
-- 1780 BC, Hammurabi, Code of Law
 
S

Skip Montanaro

Kamus> Missed that.

Kamus> Is there a search on python.org that only searches docs? That
Kamus> would be really helpful.... I keep coming up with gobs of
Kamus> irrelevant stuff on my searches.

I've been meaning to put together some Google tips for python.org. Your
plea goaded me into action. The beginnings are here:

http://www.python.org/cgi-bin/moinmoin/GoogleTips

Many more are possible based upon the many mailing lists and documents the
site contains. Feel free to add to what's there.

Skip
 

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

Forum statistics

Threads
474,172
Messages
2,570,934
Members
47,478
Latest member
ReginaldVi

Latest Threads

Top