473,471 Members | 1,729 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

logging module: removing handlers

I have just discovered a bug in my code using the logging module, due
to
handlers not being closed properly. The issue was that I called the
function
removeHandler and I assumed that it took care of closing the handler,
but it did not.
Looking at the source code of logging/__init__.py I discovered that it
is
implemented as follows:

def removeHandler(self, hdlr):
"""
Remove the specified handler from this logger.
"""
if hdlr in self.handlers:
#hdlr.close()
hdlr.acquire()
try:
self.handlers.remove(hdlr)
finally:
hdlr.release()

The question is: why in the hell the "hdlr.close()" line is
commented??
I discovered this because we had locks in our production database
(we were logging on the DB) and it was not easy to spot the source of
the problem, so I would like to know the rationale for not closing
the handler in removeHandler.

Michele Simionato
Nov 21 '07 #1
4 6920
Michele Simionato schrieb:
I have just discovered a bug in my code using the logging module, due
to
handlers not being closed properly. The issue was that I called the
function
removeHandler and I assumed that it took care of closing the handler,
but it did not.
Looking at the source code of logging/__init__.py I discovered that it
is
implemented as follows:

def removeHandler(self, hdlr):
"""
Remove the specified handler from this logger.
"""
if hdlr in self.handlers:
#hdlr.close()
hdlr.acquire()
try:
self.handlers.remove(hdlr)
finally:
hdlr.release()

The question is: why in the hell the "hdlr.close()" line is
commented??
I discovered this because we had locks in our production database
(we were logging on the DB) and it was not easy to spot the source of
the problem, so I would like to know the rationale for not closing
the handler in removeHandler.
I can only guess - but I'd say if you can do

foo.removeHandler(h)

you can do

foo.removeHandler(h)
h.close()

easily. But not

foo.removeHandler(h) # implicit closing
bar.addHandler(h)

It does kind of make sense if you decouple the life-cycles IMHO.

Diez
Nov 21 '07 #2
On Nov 21, 10:23 am, "Diez B. Roggisch" <de...@nospam.web.dewrote:
I can only guess - but I'd say if you can do

foo.removeHandler(h)

you can do

foo.removeHandler(h)
h.close()

easily. But not

foo.removeHandler(h) # implicit closing
bar.addHandler(h)

It does kind of make sense if you decouple the life-cycles IMHO.

Diez
But what is the use case for removing an handler without closing it?

Michele Simionato
Nov 21 '07 #3
Michele Simionato wrote:
On Nov 21, 10:23 am, "Diez B. Roggisch" <de...@nospam.web.dewrote:
>I can only guess - but I'd say if you can do

foo.removeHandler(h)

you can do

foo.removeHandler(h)
h.close()

easily. But not

foo.removeHandler(h) # implicit closing
bar.addHandler(h)

It does kind of make sense if you decouple the life-cycles IMHO.

Diez

But what is the use case for removing an handler without closing it?
Having thought more about this, it _has_ to be that way - think of one
handler attached to several loggers. Removing AND closing it from one would
render it useless for others. You can't want that to happen.

Diez
Nov 21 '07 #4
On Nov 21, 11:08 am, "Diez B. Roggisch" <de...@nospam.web.dewrote:
Having thought more about this, it _has_ to be that way - think of one
handler attached to several loggers. Removing AND closing it from one would
render it useless for others. You can't want that to happen.
You have a point.
Nov 21 '07 #5

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

Similar topics

0
by: max | last post by:
I have an application which calls a module runx, in runx I import logging and get a logger add handlers. I want to be able to rename the file created by fileHandler. several problems, I can't...
0
by: Robert.Schmitt | last post by:
I found that the configuration system of the new logging package of Python 2.3 has some unintuitive idiosyncracies that are worth mentioning because they can cost you quite some development time...
23
by: Rotem | last post by:
Hi, while working on something in my current project I have made several improvements to the logging package in Python, two of them are worth mentioning: 1. addition of a logging record field...
0
by: robert | last post by:
As more and more python packages are starting to use the bloomy (Java-ish) 'logging' module in a mood of responsibility and as I am not overly happy with the current "thickener" style of usage, I...
0
by: Christoph Haas | last post by:
Evening, I have an application that is running in an endless loop processing an incoming queue. Every run is supposed to write a log file about the run and then close it again. While the...
7
by: flupke | last post by:
Hi, i'm getting errors with the log module concerning RotatingFileHandler. I'm using Python 2.4.3 on Windows XP SP2. This used to work in previous python versions but since i upgraded to 2.4.3...
3
by: Chris Shenton | last post by:
I am setting up handlers to log DEBUG and above to a rotating file and ERROR and above to console. But if any of my code calls a logger (e.g., logging.error("foo")) before I setup my handlers, the...
4
by: Frank Aune | last post by:
Hello, I've been playing with the python logging module lately, and I manage to log to both stderr and MySQL database. What I'm wondering, is if its possible to specify the database handler in...
3
by: Lowell Alleman | last post by:
Here is the situation: I wrote my own log handler class (derived from logging.Handler) and I want to be able to use it from a logging config file, that is, a config file loaded with the...
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
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
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.