Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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:
$log->('some global log message'); $job_log->('some log message specific to this job');
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.

In reply to Daemon, log4perl & stderr/stdout by saberworks

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-25 13:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found