log4perl and Proc::Daemon

Chisel Wright chisel at herlpacker.co.uk
Tue Jul 8 11:13:38 BST 2008


Sorry for taking the list off-topic, but I'm getting myself tied up in
knots trying to resolve this issue.

The key ingredients in this mix are Proc::Daemon, Log::Log4perl, and
some modules that log via:

  package MyApp::Logger;
  # usual stuff ...

  # initialise the logger
  Log::Log4perl->init_once( $log4perl_conf_file  );

  sub app_logger :Export() {
    my $category    = shift;
    $category       = defined $category ? $category : 'MyApp';
    return get_logger($category);
  }

I've reduced my daemonizing script to:

  use Proc::Daemon;
  use Proc::PID::File;
  use MyApp::Logfile qw(app_logger);

  if (my $pid = Proc::Daemon::Fork) { # parent
    # nothing here
  }
  else { # child
    app_logger->debug('pre-daemon message');

    # daemonize
    Proc::Daemon::Init;

    # re-open stderr and stdout
    open(*STDOUT, '>>', '/tmp/test.log');
    open(*STDERR, '>&STDOUT');

    # test to make sure we see stuff there
    warn  "warn()\n";
    print "print()\n";

    app_logger->debug('post-daemon message');

    # child loop
    while (1) {
      app_logger->debug('child tick');
      sleep(60);
    }
  }
  
In the logs I'm seeing:

  warn()
  print()
  Cannot write to '/var/data/xtracker/logs/xtracker.log': Bad file
   descriptor at /usr/local/share/perl/5.8.8/Log/Dispatch/File.pm line 134.

Do I need to re-init the Log::Log4perl somehow? I'm assuming (yeah, I
know) that the FH get closed in a similar manner to stdout/stderr.
If I do, any ideas what impact (if any) this will have on an active
apache+mod_perl process that using the same logger?

Chiz
-- 
Chisel Wright
e: chisel at herlpacker.co.uk
w: http://www.herlpacker.co.uk/

  When you fail to design for evil, you have failed your community.


More information about the london.pm mailing list