[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

writing from 3 sources to 1 file

pere.noel

8/5/2006 4:59:00 AM

i've an app with 2 daemons, i'd like to write all the log messages to
the same file.

then i suppose i need to lock the file when one source is writing and
wait the file is unlocked for the other ?

how this could be done in ruby, or is it automagic ))

--
une bévue
6 Answers

Robert Klemme

8/5/2006 8:52:00 AM

0

Une bévue wrote:
> i've an app with 2 daemons, i'd like to write all the log messages to
> the same file.
>
> then i suppose i need to lock the file when one source is writing and
> wait the file is unlocked for the other ?
>
> how this could be done in ruby, or is it automagic ))

There is some locking support but watch out for NFS. There is Ara's
solution at http://raa.ruby-lang.org/project...

An alternative approach is to have a centralized logger daemon which is
the only process writing the file. Your sources then could connect to
it via DRB. This might even be more efficient because the logger daemon
can keep the file open and even queue a number of log messages to write
in order to decouple file writing and your sources activities.

Kind regards

robert

pere.noel

8/5/2006 9:34:00 AM

0

Robert Klemme <shortcutter@googlemail.com> wrote:

>
> There is some locking support but watch out for NFS. There is Ara's
> solution at http://raa.ruby-lang.org/project...
>
> An alternative approach is to have a centralized logger daemon which is
> the only process writing the file. Your sources then could connect to
> it via DRB. This might even be more efficient because the logger daemon
> can keep the file open and even queue a number of log messages to write
> in order to decouple file writing and your sources activities.

ok thanx, in fact two of the tree sources are allready daemons ))
--
une bévue

Ara.T.Howard

8/5/2006 2:26:00 PM

0

Logan Capaldo

8/5/2006 2:31:00 PM

0


On Aug 5, 2006, at 1:00 AM, Une bévue wrote:

> i've an app with 2 daemons, i'd like to write all the log messages to
> the same file.
>
> then i suppose i need to lock the file when one source is writing and
> wait the file is unlocked for the other ?
>
> how this could be done in ruby, or is it automagic ))
>
> --
> une bévue
>

If you are just writing on a line by line basis, OS buffering should
mitigate the need to do anything special, as long as you don't mind
have lines interleaved from different daemons.

e.g.

a whole line from daemon1
a whole line from daemon1
a whole line from daemon2
a whole line from daemon1
a whole line from daemon1



pere.noel

8/5/2006 5:26:00 PM

0

Logan Capaldo <logancapaldo@gmail.com> wrote:

>
> If you are just writing on a line by line basis, OS buffering should
> mitigate the need to do anything special, as long as you don't mind
> have lines interleaved from different daemons.

i don't want interleave, i have 2 different daemons and one app as
sources, the trio run asynchronously. I don't report in a line by line
basis too.

i think i'll have a look upon Log4r.
i think (may be) with Log4r i might be able to write log msg thru socket
then be able to debugg thru de net.

--
une bévue

pere.noel

8/5/2006 5:26:00 PM

0

<ara.t.howard@noaa.gov> wrote:

> you also need to make sure that buffers are flushed after each write or the
> msgs will be interleaved.
>

thanx for your long a vlear answer !

> if you're on windows you'll need one on these

unfortunately i forgot to mention i'm unning on MacOS X...

--
une bévue