473,545 Members | 2,009 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.basicCo nfig()
logFile = logging.handler s.RotatingFileH andler("/var/log/user/movies.log",'a' ,2000,4)
logFile.setLeve l(logging.INFO)
formatter = logging.Formatt er(hostname + ' %(asctime)s %(message)s',da tefmt='%Y-%m-%d.%H:%M')
logFile.setForm atter(formatter )
logging.getLogg er('').addHandl er(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 5812
Kamus of Kadizhar <ya*@NsOeSiPnAe Mr.com> wrote in message news:<pa******* *************** ******@NsOeSiPn AeMr.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*@NsOeSiPnAe Mr.com> wrote in message news:<pa******* *************** ******@NsOeSiPn AeMr.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
3382
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 should be kept in mind while using either technique? And, of course, which is considered to be the better one? TIA
5
11237
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
390
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 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...
1
3124
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 that when appending data to the log file that each instance might lock the log file and block the other instances until it is finished writing to...
4
2169
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 write the information about user name, filename upload, filesize, date and time of uploading into the log file. (The name of the log file is...
2
2521
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 re-attempt with a "being used by another process" exception. I then have to recycle the w3wp.exe process, IIS, and sometimes re-deploy the application...
1
1114
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, the file is loaded and displayed in a form for the administrator to review. Now it seems there are (occasionally) times when the web-app fails...
2
1605
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 Framework. The read/write lock on the session object set by one request is being relinquished to a second request BEFORE the first request has ended. You...
4
1841
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 is truly for querying, and Crystal Reports is more a reporting tool). The only way I've found to do this so far is to execute my select in C#, then...
13
11115
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 writes a specific string to the log file. My original program (MKS Toolkit shell program) which keeps running "grep" checking the "exit string" on...
0
7409
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...
0
7921
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...
0
7771
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...
0
5982
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5343
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4958
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...
0
3446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1900
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
1
1023
muto222
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.