[Mimedefang] Logging without syslog

Michiel Brandenburg apex at xepa.nl
Sat Nov 1 17:41:29 EDT 2008


Kelly Jones wrote:
> I want to log stuff in mimedefang, but dislike syslog because it drops
Never had this happen to me, but then you millage may vary.

> packets/loglines, and am too lazy to install syslog-ng.
Urm take a look at our signature :)  But installing another syslog might 
  in the long run be the best option, take a look at rsyslogd.  We use 
it in our virtual machines to send all logs to a central log server.

> My obvious thought is to do this in my subroutines:
> local(*A);open(A,">>mylogfile");print A "my stuff\n";close(A);

> Problem: since mimedefang is multithreaded, 2+ slaves may have
> mylogfile open for append at the same time, right?
Not too sure that this will be a problem

> Thoughts? Can I do some sort of locking?
Sure, you can use the following (ripped from internet somewhere):

use Fcntl qw(:flock :seek);
open(DAT,">>$mylogfile") || die("Cannot Open File");
flock(DAT, LOCK_EX);
# will also need to seek to the end of the file as there can
# be some time between the open and the flock command ( another
# process just wrote something, but your pointer did not notice this
# so seek to then end again.
seek(DAT, 0, SEEK_END);
print DAT "$sitename\|$siteurl\|$description\n";
close(DAT);  # also releases the lock.

PS: watch out with flock on NFS mounts ... heard that only dotlocks work 
on NFS, but then I could be wrong.

But imho you will still have to solve some other problems installing 
another syslog will handle for you.  What were to happen if more than 
one thread wants to report something ? I would not feel comfortable with 
forcing one thread to wait till some other reports something. For each 
write you will have to open / lock etc, leading to overhead. Time taken 
for you to solve this properly will probably be longer than installing / 
configuring the syslog correctly :) Also syslog for instance gives u 
"free" extra's, logging to another server (some with reliable delivery), 
post processing (some lines we are never interested in etc), failing 
back to file based logging till the real server is back etc.
My advice .. use the right tool for the job .. don't try to make the 
tool yourself unless you know what you are doing.

--
Michiel Brandenburg



More information about the MIMEDefang mailing list