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

shared logs and multiple configurations

Hi all,

I've apparently tied myself up a bit using the logging package.

In my project, I have a core set of model and controller classes that
set up their logging using logging.fileConfig(). So far, so good.

But I use these core classes from a bunch of different places.
Sometimes from within a CherryPy server, sometimes batch jobs run from
a command line, sometimes from Windows services (also written in
Python). Ah, the beauty of OO design.

I would like to have a series of logs: a shared log for the core
classes (which would log messages from the core classes, regardless of
how they were invoked), a different one for CherryPy related stuff, a
third one for batch jobs run from the command line, a fourth for the
windows services. I'd alsolike to have the logs rotate automatically
using the TimedRotatingFileHandler classes. Oh, and I'd like to do as
much setup thru the configuration files and logging.fileConfig() as
possible.

So my questions are:

1) Can I share log files between processes? Log messages seem to get
written, but when it comes time to roll over a log, I generally get a
"IO operation on closed file" error. (I'm thinking that I may have to
set up a logging service if I want to do this, but I'm hoping there's a
simpler way.)

2) When I want to use logging from within a multi-threaded server
(built using the Threading module), do I create one global logger
reference, and then have each thread refer to that instance, or do I
have each thread grab it's own reference using getLogger()?

3) It seems like you can't make multiple calls to logging.fileConfig().
If I call this twice with different ini files, it appears that any
handlers set up in the first call are silently dropped when the second
call is made. (Strangely, log messages sent to loggers set up in the
first call seem to just be silently dropped.) Am I diagnosing this
behavior properly? Is there a way
to work around it?

Platform is Python 2.4.2 on Windows.

Many thanks!

Chris

Jun 8 '06 #1
1 1677
Chris Curvey wrote:
1) Can I share log files between processes? Log messages seem to get
written, but when it comes time to roll over a log, I generally get a
"IO operation on closed file" error. (I'm thinking that I may have to
set up a logging service if I want to do this, but I'm hoping there's a
simpler way.)
For multi-process logging, I would advise that all processes use a
SocketHandler to send their events to a listener. You can use the
example code in the documentation at

http://docs.python.org/lib/network-logging.html

to get a working example of a server which listens on a socket and
processes logging events received via the socket.
2) When I want to use logging from within a multi-threaded server
(built using the Threading module), do I create one global logger
reference, and then have each thread refer to that instance, or do I
have each thread grab it's own reference using getLogger()?
Logger instances are singletons, so multiple calls to getLogger() with
a given name will always return the same instance. There's usually no
need to create a single global reference, though you could for example
create a logger as a class attribute in your Thread subclass (assuming
you're subclassing Thread), or an appopriate class which implements the
functionality which runs in different threads.
3) It seems like you can't make multiple calls to logging.fileConfig().
If I call this twice with different ini files, it appears that any
handlers set up in the first call are silently dropped when the second
call is made. (Strangely, log messages sent to loggers set up in the
first call seem to just be silently dropped.) Am I diagnosing this
behavior properly? Is there a way
to work around it?


fileConfig() is not meant to do incremental configurations, so it does
its best to disable any previous configuration.It does this by clearing
out the list of previously defined handlers and disabling any
previously defined loggers. You can find the code easily enough and
comment it out if you wish not to disable old loggers.

Regards,

Vinay Sajip

Jun 9 '06 #2

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

Similar topics

3
by: alanrn | last post by:
I would like to start a dialog on how to implement the equivalent functionality of UNIX shared memory in .NET. I work with a factory automation system. The bulk of the system is written in C/C++....
2
by: Gary Feldman | last post by:
I didn't get any good answers to my previous question about unit testing, so let me rephrase the question: As near as I can see, it's possible to add arbitrary configurations to a C# project in...
2
by: David Wagner | last post by:
Hi, I am looking at wanting to configure and manage some Performance Monitor logs through a C# application. Specifically, I want to be able to define and configure named performance log...
3
by: Philip Tepedino | last post by:
I'm having an odd problem. My website's session state is getting shared between users! This problem only happens when a user tries to access the site from inside our corporate LAN. The user,...
9
by: Bob Day | last post by:
VS 2003, vb.net , sql msde... I have an application with multiple threads running. Its a telephony application where each thread represents a telephone line. For code that would be the same...
10
by: Rich Kucera | last post by:
Holding all versions at 5.0.4, Multiple stacks with multiple-version configurations inevitable Will have to wait to see what the impact of problems such as http://bugs.php.net/bug.php?id=33643 ...
0
by: Dmitrii | last post by:
My C# project has 4-configuration: Debug, Release, DebugPlus, and ReleasePlus. In each of these configurations the C# program should consume (be "linked" to) a different Assembly.dll build...
11
by: eBob.com | last post by:
I have this nasty problem with Shared methods and what I think of as "global storage" - i.e. storage declared outside of any subroutines or functions. In the simple example below this "global"...
6
by: Randy Shore | last post by:
I have a shared Access mdb that was originally written in A2000. The database is large, around 40 tables, 40 forms (many with multiple sub-forms), and 100s of reports. The database is not split,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
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...

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.