Disabling Logging Handler for a Second

VenkataRamaKrishna Boddu bvrkchowdary at yahoo.co.in
Fri May 22 07:26:49 EDT 2009


Hi All,

Is there any way, I can disable one logging Handler, while other Log Handler are still available for servicing.....

Please see the below code. It explains my Problem better.
I actually reduce the size of problem, to make it understandable faster


------------------------------------------------------------------------------------------------------------------------------
import logging;
import sys;

thelog = logging.getLogger('app.scsi.cdb');
strmHdlr = logging.StreamHandler(sys.stdout);
fHdlr = logging.FileHandler('a.log')

thelog.addHandler(strmHdlr);
thelog.addHandler(fHdlr);
thelog.setLevel(logging.DEBUG);

thelog.info('Hello Python Logger');
thelog.info('This is Venkata Rama Krishna');

## Now, I want to disable the strmHdlr for some moment without
## actually removing the Handler from logger Object,
## I want to say something like
##
## thelog.disable('StreamHandler');
##
## So., that it disables all the Stream Handlers attached to the Logger Object

## The Need for me is that, I should write My Email Id only to File Stream
## and because of some reasons of moduler design, I don't have references to the
## both the Handlers

## Here, I don't have want to do the StreamHandler removing stuff and adding it again later on
thelog.removeHandler(strmHdlr);
thelog.info('Email: bvrkchowdary at yahoo.co.in');


## Now, I want to re-enable the strmHdlr without
## actually adding the Handler to the logger Object
## I want to say something like
##
## thelog.enable('StreamHandler');
##
## So., that it disables all the Stream Handlers attached to the Logger Object

## Now, I can write my Phone Number to both the Streams

## Here, I don't want to do the Stream Handler adding stuff 
thelog.addHandler(strmHdlr);
thelog.info('Phone no: +91-9985778581');
------------------------------------------------------------------------------------------------------------------------------

Thanking you,
Venkata Rama Krishna Boddu  


      Cricket on your mind? Visit the ultimate cricket website. Enter http://beta.cricket.yahoo.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090522/19d3b501/attachment.html>


More information about the Python-list mailing list