473,609 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Logging to a file and closing it again properly (logging module)

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 'logging' module is generally working
well (even though the documentation makes me miss some proper examples
how everything works together) I can't seem to close the log file again
to open a new one.

This is basically what I'm doing:

log = logging.getLogg er("myapplicati on")
log.addHandler( logging.FileHan dler("/tmp/testfile"))
log.setLevel(lo gging.INFO)
log.info("foo")

Now I'm missing a way to tell this handler to go away. Through 'ipython'
I found out there is a log.handlers array that contains all the
handlers. Perhaps I could delete all of them but I'm sure there is a
more proper way to close files again.

Googling found me:

.>>> logging._handle rs.clear()
.>>> logging.root.ha ndlers = []
.>>> for l in logging.Logger. manager.loggerD ict.values():
.>>> l.handlers = []

But this looks really really ugly. I don't like to mess with the gears
in the 'logging' module.

Ideas?

Kindly
Christoph
Jun 12 '06 #1
0 1251

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

Similar topics

5
11255
by: j vickroy | last post by:
Hello, I'm trying to understand the behavior of the Python 2.3 logging module (MS Windows 2k) with regard to RotatingFileHandler. The following script illustrates a puzzling problem. What is wrong with this script? Thanks, -- jv
0
1654
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 and are not documented elsewhere. I used the logging configuration file shown below. My aim was to log only the INFO messages, but log DEBUG messages for one particular module (called webTestLogin.py).
6
10871
by: Ville Vainio | last post by:
Just posting this for the sake of google: Like everyone else, I figured it's time to start using the 'logging' module. I typically want to dump "info" level (and up) log information to screen, and "debug" level (and up) to a log file for in-depth analysis. This is for scripts, so date/time/severity information is not wanted. I assumed such a simple use case would have an example in the docs (py 2.4), but no luck.
7
2418
by: Jed Parsons | last post by:
Hi, I'm using the logging module for the first time. I'm using it from within Zope Extensions. My problem is that, for every event logged, the logger is producing multiple identical entries with the timestamp the same down to the millisecond. Is this something I'm doing wrong?
7
8559
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 i get these errors: Traceback (most recent call last): File "C:\Python24\lib\logging\handlers.py", line 71, in emit if self.shouldRollover(record):
2
2467
by: Robert | last post by:
Hi all I have been trying to set up a framework with logging implemented using the built in Python logging module. For better or worse, I have decided to base the logger names on the module names. This means that I am using multiple layers of name, eg logging.getLogger("a.b.c"). I am also using logging.config to load a file configuration but have been experiencing some unexpected behaviour. If for instance I have something resembling...
4
6931
by: Michele Simionato | last post by:
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:
3
6415
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 logging.config.fileConfig() function. Let say my logging class is called "MyLogHandler" and it's in a module called "mylogmodule", I want to be able to make an entry something like this in my logging config file:
5
2685
by: =?ISO-8859-2?Q?Lech_Karol_Paw=B3aszek?= | last post by:
Hello. I'm trying to make a daemon and I want to log to a file its activity. I'm using logging module with a configuration file for it (loaded via fileConfig()). And now I want to read logging config file before daemonize the program because the file might not be accessible after daemonization. OTOH while daemonizing I am closing all opened file descriptors - including those opened for logging.
0
8130
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8076
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8573
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8541
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8222
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8406
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5510
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2531
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 we have to send another system

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.