473,395 Members | 1,823 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.

File locking and logging

Thanks to Robert Brewer, I got enough insight into logging to make it work....

Now I have another issue: file locking. Sorry if this is a very basic
question, but I can't find a handy reference anywhere that mentions this.

When a logger opens a log file for append, is it automatically locked so
other processes cannot write to it? And what happens if two or more
processes attempt to log an event at the same time?

Here's my situation. I have two or three workstations that will log an
event (the playing of a movie). The log file is NFS mounted and all
workstations will use the same log file. How is file locking implemented?
Or is it?

I've read through the various logger doc pages and this is never mentioned.

The logging code that works (for me at least) is this:

logging.basicConfig()
logFile = logging.handlers.RotatingFileHandler("/var/log/user/movies.log",'a',2000,4)
logFile.setLevel(logging.INFO)
formatter = logging.Formatter(hostname + ' %(asctime)s %(message)s',datefmt='%Y-%m-%d.%H:%M')
logFile.setFormatter(formatter)
logging.getLogger('').addHandler(logFile)
logging.warning(movieName)
logFile.flush()
logFile.close()

Any thoughts are appreciated....

Thanks,

--Kamus

--
o |
o__ >[] | A roadie who doesn't ride a mountain bike has no soul.
,>/'_ /\ | But then a mountain biker who doesn't ride a road bike has no legs...
(_)\(_) \ \ | -Doug Taylor, alt.mountain-bike

Jul 18 '05 #1
2 5789
Kamus of Kadizhar <ya*@NsOeSiPnAeMr.com> wrote in message news:<pa****************************@NsOeSiPnAeMr. com>...
Thanks to Robert Brewer, I got enough insight into logging to make it work....

Now I have another issue: file locking. Sorry if this is a very basic
question, but I can't find a handy reference anywhere that mentions this.

When a logger opens a log file for append, is it automatically locked so
other processes cannot write to it? And what happens if two or more
processes attempt to log an event at the same time?

Here's my situation. I have two or three workstations that will log an
event (the playing of a movie). The log file is NFS mounted and all
workstations will use the same log file. How is file locking implemented?
Or is it?


No file locking is attempted by current logging handlers with respect
to other processes - an ordinary open() call is used. Within a given
Python process, concurrency support is is provided through threading
locks. If you need bullet-proof operation in the scenario where
multiple workstations are logging to the same file, you can do this
through having all workstations log via a SocketHandler to a
designated node, where you run a server process which locally logs to
file events received across the network. There is a working example of
this in the Python 2.4 docs.

Best regards,
Vinay Sajip
Jul 18 '05 #2
Kamus of Kadizhar <ya*@NsOeSiPnAeMr.com> wrote in message news:<pa****************************@NsOeSiPnAeMr. com>...
Thanks to Robert Brewer, I got enough insight into logging to make it work....

Now I have another issue: file locking. Sorry if this is a very basic
question, but I can't find a handy reference anywhere that mentions this.

When a logger opens a log file for append, is it automatically locked so
other processes cannot write to it? And what happens if two or more
processes attempt to log an event at the same time?

Here's my situation. I have two or three workstations that will log an
event (the playing of a movie). The log file is NFS mounted and all
workstations will use the same log file. How is file locking implemented?
Or is it?


No file locking is attempted by current logging handlers with respect
to other processes - an ordinary open() call is used. Within a given
Python process, concurrency support is is provided through threading
locks. If you need bullet-proof operation in the scenario where
multiple workstations are logging to the same file, you can do this
through having all workstations log via a SocketHandler to a
designated node, where you run a server process which locally logs to
file events received across the network. There is a working example of
this in the Python 2.4 docs.

Best regards,
Vinay Sajip
Jul 18 '05 #3

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

Similar topics

5
by: Micha³ Wo¼niak | last post by:
Hi again The Question of Logs, part II. :) What are the advantages/disadvantages of using syslog() to do the logging rather than writing the logs with fopen(), fwrite() and fclose()? What...
5
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...
0
by: Kamus of Kadizhar | last post by:
Thanks to Robert Brewer, I got enough insight into logging to make it work.... Now I have another issue: file locking. Sorry if this is a very basic question, but I can't find a handy reference...
1
by: Amy L. | last post by:
I have a console application that at any time can have multiple instances of it running. I want to log information form each of these instances into one central log file. However, I am concerned...
4
by: HNguyen | last post by:
Hi, I have a Web application in ASP.NET. My Application allows the users upload files into the server after checking their user names and passwords. For each transaction, the Web program will...
2
by: Doug Oliver | last post by:
I've got an intermittent problem when trying to write to a text file (used as a log). ASPNET has modify on folder, and at times logs to file, then I get a null reference exception, followed on...
1
by: Roger Helliwell | last post by:
My web app writes all error/diagnostic messages to an error file in Xml format. It seemed to be working fine, until I wrote a Windows app that listens for changes in this file. If the file changes,...
2
by: Nick | last post by:
We have recently discovered that on our production environment certain aspx files, two to be certain, are displaying a behaviour we understand ought not to be possible under the (ASP).Net...
4
by: chad.a.morris | last post by:
I'm new to Crystal Reports, so this may be a dumb problem, but I just can't figure it out. Basically, I want to control the selected data in the C# code as opposed to Crystal Reports (since SQL...
13
by: George | last post by:
Hi, I am re-writing part of my application using C#. This application starts another process which execute a "legacy" program. This legacy program writes to a log file and before it ends, it...
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.