|P is for Practical|
Daemon, log4perl & stderr/stdoutby saberworks (Curate)
|on May 27, 2008 at 21:10 UTC||Need Help??|
saberworks has asked for the
wisdom of the Perl Monks concerning the following question:
I have a question about forwarding STDERR & STDOUT to a log4perl object on a per-job basis (inside a while loop). Here is some background:
I have a daemon program (uses Proc::Daemon) that grabs "jobs" to process from a database. Once it has the "job" it uses the info from the database to shell out and "process" the job. The processing is basically calling a bunch of external programs in sequence and making sure the output of said programs looks sane. There's probably 8-10 steps in a "job" that are all handled by different program.
When each new job is started, a new Log::Log4perl "category" is created and this category is logged to that job's "run path" (the directory in which the commands are run). I can then call:
This allows me to log messages specific to a job to one log file and all other messages to a global log file. This is all working fine.
Although we hope that there will never be errors with the various external programs, we are more realistic and we know that we will at some point have to debug some errors. So I would like to forward the STDERR and STDOUT from these external programs to my $job_log log4perl object.
When Proc::Daemon runs, it somehow takes over STDOUT and STDERR so I don't see the messages. I'm not sure this matters.
The question is, how do I make it so messages written to STDOUT and STDERR are forwarded (and timestamped) by Log::Log4perl?
I have seen this FAQ answer:
Some module prints messages to STDERR. How can I funnel them to Log::Log4perl?
Which is somewhat related but doesn't really answer the question. They are using a DEBUG function call as opposed to an object $job_log->debug() call. I'm not sure this distinction matters. Any help is greatly appreciated.