468,251 Members | 1,391 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,251 developers. It's quick & easy.

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 4345
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Micha³ Wo¼niak | last post: by
reply views Thread by Kamus of Kadizhar | last post: by
1 post views Thread by Amy L. | last post: by
2 posts views Thread by Doug Oliver | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.