[Chicago-talk] writing a log with Cron, Daemons, Perl

Jay Strauss me at heyjay.com
Fri Sep 5 09:50:37 CDT 2003


I'm using Net::Server::Daemonize qw(daemonize) to turn my program into a
daemon.

sometimes I start this program from the command line, some times via cron.
I'd like to have a log file that contains everything that would normally go
to STDERR plus all the messages my program spits out.

I'm running into a couple of problems:

1) how do I get stuff into my log file without closing the file handle?  I
tried $|++;  For example:

use Net::Server::Daemonize qw(daemonize);
daemonize ("jstrauss","jstrauss","/home/jstrauss/test.pid");
open (LOG,">/home/jstrauss/bin/test.log");
print LOG "Help\n";
while (1) {
}

my message never gets printed to the file.

2) how would I redirect all of STDERR so that my messages appear in the
proper order?  for example:
#!/usr/bin/perl
open (LOG,">/home/jstrauss/bin/test.log");
open (STDERR, ">>&LOG");
$|++;
print LOG "yep\n";
die "you jerk";

:~/bin> cat test.log
you jerk at /home/jstrauss/bin/jay line 16.
yep

*** notice the messages above are in the reverse order that they occured in
the program.

Lastly, is there some error logging module I should be using?
Jay




More information about the Chicago-talk mailing list