Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Writing to a log file without colliding

by KeighleHawk (Scribe)
on Aug 17, 2004 at 20:15 UTC ( [id://383784]=note: print w/replies, xml ) Need Help??


in reply to Writing to a log file without colliding

I think what you are after is a Queue. Your processes can write to the queue, and a seperate, single process can pop them off the queue and put them in the log file.

One place I worked used UNIX queues and two small C programs to accomplish this. I did not write, nor remember the code but as I recall it was fairly short.

There is at least one Perl Queue module (Queue::Base) though I have no experience with it or how it works.

There is also POE which might work for you.

As someone mentioned, if you have access already to a database like Oracle which has a queue implementation, or perhaps something like MQ then that would work. Obviously it is overkill if you need it only for a single logging queue, but if it is there already...

Depending on your processes and versions of Perl, perhaps you can do a single process for all of them and do something clever with threads if you are feeling adventurous.

Depending on your access and the temperment of your Sys Admins, you might be able to write to the system file (syslog) and then either use that as your log file or reap it with another single process. Depends on what you want this for and the volume of messages you expect, I guess.

As a last, low tech model, pick a directory and have every process write seperate files for each message to the directory. Use a nameing convention/time stamp or some such to determine file/message order. You can also use the naming convention to distinguish files in process (e.g. "dot" files are being written to. when finished the process can remname them to remove the leading '.'). Then, have another, again single, process reap that directory, transfer the messages to the log file and delete the temp files.

  • Comment on Re: Writing to a log file without colliding

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://383784]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2024-04-19 01:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found