Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Multiple processes logging to single file

Reply
Thread Tools

Multiple processes logging to single file

 
 
pachl
Guest
Posts: n/a
 
      05-21-2008
When using the native ruby logger, is it save to have multiple
processes writing to the same log file?

For instance, I have the following ruby source example:

# test.rb
require 'logger'

log = Logger.new('/tmp/RLOG')

20.times do
log.error "PID: #{$$}"
sleep 1
end

log.close
# end test.rb

Then I execute like so:

$ ruby test.rb & ruby test.rb & ruby test.rb

After inspection of the log file, each process logged 20 times, all
messages interleaved of course. It looks like it works, but am I
delusional? I'm on an OpenBSD box. Does the OS handle caching/writing
from multiple sources?

-pachl
 
Reply With Quote
 
 
 
 
Phillip Gawlowski
Guest
Posts: n/a
 
      05-21-2008
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

pachl wrote:

| After inspection of the log file, each process logged 20 times, all
| messages interleaved of course. It looks like it works, but am I
| delusional? I'm on an OpenBSD box. Does the OS handle caching/writing
| from multiple sources?

Yes, the OS should manage that (it is file-system level, rather than
userspace level). However, you can tweak your code to have
'transactional' logs (i.e. that every application logs a meaningful
chunk of information in one go).

Anyway, the file system and drivers take care of the actual writing.

Though, having everything log into one logfile *may* result in fractured
files, or odd race conditions and/or deadlocks. It might be saner to log
each process to its own file.

- --
Phillip Gawlowski
Twitter: twitter.com/cynicalryan
Blog: http://justarubyist.blogspot.com

Don't over-comment.
~ - The Elements of Programming Style (Kernighan & Plaugher)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkg0tLAACgkQbtAgaoJTgL9zpACfR/jr2oNQSrRc34nr7a6/rTX1
oGcAnj/BTPpEjGy9eZJz2NHYXBWPf5yk
=zdqV
-----END PGP SIGNATURE-----

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Controlling processes and what to "feed" other processes Marc Heiler Ruby 1 05-24-2009 05:37 PM
resolve single line with multiple items into mutliple lines, single items ela Perl Misc 12 04-06-2009 06:47 PM
how to run multiple processes from a single process? mandydhaliwal@gmail.com C++ 8 08-01-2006 05:00 PM
Multiple worker processes for a single application in a applicationpool Abhishek Srivastava ASP .Net 9 02-03-2004 06:28 PM
How do I: Main thread spawn child threads, which child processes...control those child processes? Jeff Rodriguez C Programming 23 12-09-2003 11:06 PM



Advertisments