Adler has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

i am trying to write a program that does the follwoing:

1. Open 3 threads which write to the same filename.

2. Every 24h one of the threads will close the file (which all 3 threads write too and open a new file for all the 3 threads).

A friend of my was trying to help me with this task and he wrote me a program that uses log4perl and SIG, but the this code have a problem, after i send the SIG kill -QUIT pid it closed the file but doesn't write again to the new file (i change the file name in the conf file before i send the SIG):

here is the code:
#!/usr/bin/perl -w use threads; use threads::shared; use Log::Log4perl qw(get_logger :levels); Log::Log4perl->init_and_watch('/home/kg/log.conf', 'QUIT'); my $logger = get_logger(); $logger->level($INFO); my $thr1 = threads->create(\&thread1); my $thr2 = threads->create(\&thread2); my $thr3 = threads->create(\&thread3); $SIG{INT} = sub { my $sig = shift; my $tid = threads->tid(); print "Thread $tid received $sig\n"; foreach my $thr (threads->list()) { print "Sending QUIT to thread with tid ", $thr->tid, "\n"; $thr->kill('QUIT'); } }; print "PID: $$\n"; while () { sleep 10; my $date = `date`; chomp $date; print $date, ": I'm the main program\n"; } sub thread1 { while () { my $logger = get_logger(); $logger->info("I'm thread1"); sleep 10; } } sub thread2 { my $logger = get_logger(); while () { $logger->info("I'm thread2"); sleep 10; } } sub thread3 { my $logger = get_logger(); while () { $logger->info("I'm thread3"); sleep 10; } }

and log.conf file:

############################################################ # A simple root logger with a Log::Log4perl::Appender::File # file appender in Perl. ############################################################ log4perl.rootLogger=ERROR, LOGFILE log4perl.appender.LOGFILE=Log::Dispatch::File log4perl.appender.LOGFILE.filename=/home/kg/myerrs.log log4perl.appender.LOGFILE.mode=append log4perl.appender.LOGFILE.layout=PatternLayout log4perl.appender.LOGFILE.layout.ConversionPattern=%d - [%r] %F %L %c +- %m%n

Remarks, before i send the SIG, i changed the file name. e.g:

log4perl.appender.LOGFILE.filename=/home/kg/myerrs.log

to

log4perl.appender.LOGFILE.filename=/home/kg/myerrs1.log

then sending kill -QUIT pid the program closed the file, creat new file myerrs1.log, but dont write to it...

My questions

1. what do i need to change that the program would write the the new file

.

2. i would like instead of a fixed string as file name to give a function that each time a SIG is sent a new filename would be generated accordnig to my function. Is it possible?