473,414 Members | 1,737 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,414 software developers and data experts.

How to log only one level to a FileHandler using python logging module.

I want a FileHandler to only log a single level say for example
logging.INFO, and nothing else.
do I need to create a custom Handler for this or is this doable with
some magic that is not documeneted somewhere?

May 16 '06 #1
1 3489
Try looking into logging.Filters:
http://docs.python.org/lib/node358.html

An example:

import logging

class InfoFilter(logging.Filter):
def filter(self, record):
return record.levelno == 20

if __name__ == "__main__":
logger = logging.getLogger()
hdlr = logging.FileHandler("blah.log")
hdlr.addFilter(InfoFilter())
logger.addHandler(hdlr)

logger.exception("ERROR WILL ROBINSON")

Cheers,
Aaron
fuzzylollipop wrote:
I want a FileHandler to only log a single level say for example
logging.INFO, and nothing else.
do I need to create a custom Handler for this or is this doable with
some magic that is not documeneted somewhere?


May 16 '06 #2

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

Similar topics

2
by: Diez B. Roggisch | last post by:
Hi, I want to introduce cmd-line dependend verbosity into my app. What do you recommend? In java, I'd use log4j, and I know that there is a log4py module. I can use that, but is there some sort...
3
by: Frantisek Fuka | last post by:
I am using the standard "logging" module included with Python and it seems it doesn't correctly identify the filename (and thus module name) from where the logging method was called. In fact, no...
1
by: Jim | last post by:
Hi, with the logging module, I am using the FileHandler formatter. Is there a setting to stop the logger from putting the same message more than once? So it would say: Message whatever...
0
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 393 open (+15) / 3315 closed (+17) / 3708 total (+32) Bugs : 908 open (+22) / 5975 closed (+49) / 6883 total (+71) RFE : 223 open...
0
by: Karlo Lozovina | last post by:
I've just upgraded to Python 2.5, SQLAlchemy 0.3.3, and py2exe 0.6.5 (the py2.5 version, yes). Simple: --- import sqlalchemy print 'Test' ---
3
by: seb | last post by:
Hi, I am writing to a file some basic information using the logging module. It is working but in the log file some line are printed several time. I had put some print debugging messages in the...
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...
5
by: =?UTF-8?B?UmFmYcWC?= Zawadzki | last post by:
Hello. As I saw in logging source - there is no lock per file during making emit() (only lock per thread). So, my question is - is it safe to log into one file using many processess uses...
2
by: Frank Aune | last post by:
Hi, Explaining this problem is quite tricky, but please bear with me. Ive got an application which uses MySQL (InnoDB) for two things: 1. Store and retrieve application data (including...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.