473,734 Members | 2,774 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 5912
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
3391
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
11274
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 what happens if two or more processes attempt to log an event at the same time? Here's my...
1
3139
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 the file. Is there anything in System.IO that can help alleviate this issue (i.e not locking the...
4
2179
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 constructed by Current Year and Current Month in my program). Is there any problems with writing into the...
2
2529
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 on the file system. Seems for some reason the filesystem cannot see the file... Moreove, if I...
1
1121
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 while trying to write to the file. Presumably this is due to the fact that the Windows app is...
2
1612
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 can imagine the myriad of ugly situations that can arise from simultaneous requests concurrently...
4
1862
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 store to an XML file, and then have the Crystal Report read the XSD and XML files. However, I...
13
11146
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 the "log files". There are no file sharing problem.
0
8946
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
9452
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
9310
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...
0
8187
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6737
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4813
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3262
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
2
2729
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.