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

Paul Baker pbaker at where2getit.com
Fri Sep 5 14:53:28 CDT 2003


On Friday, September 5, 2003, at 09:50  AM, Jay Strauss wrote:

> 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.
>
> [snip]

The other replies are total overkill for what you are trying to do. 
Jay, from what I can tell you just want everything that would normally 
go to STDERR to be written to a log, instead of being lost in oblivion 
right? Real simple. Your code above is very close, just replace LOG 
with STDERR. This will reopen the file as STDERR and everything that 
normally writes to STDERR will go to that file instead. Piece of cake.

  use Net::Server::Daemonize qw(daemonize);
  daemonize ("jstrauss","jstrauss","/home/jstrauss/test.pid");
  open (STDERR,">/home/jstrauss/bin/test.log");
  print STDERR "Help\n";
  while (1) {
    die "this will go to STDERR too!";
  }


-- 
Paul Baker

"Yes, we did produce a near-perfect republic. But will they keep it? Or 
will they, in the enjoyment of plenty, lose the memory of freedom?”
          -- Thomas Jefferson in a letter to John Adams

GPG Key: http://homepage.mac.com/pauljbaker/public.asc





More information about the Chicago-talk mailing list