ginju75 has asked for the wisdom of the Perl Monks concerning the following question:

Hello Wise Monks,

I am trying to see how I can create seperate Log files for 1. the output of a perl script and 2. the Error's and warning's in the script.

Presently I am redirecting my STDOUT and STDERR to write to files. It seems to work fine. I read somewhere the use of  $main::logfile.

I could not quiet get it. Any thoughts of how to create say scriptnameOUT.log and scriptnameERR.log, other than redirecting it to specific files as I do?

Thank you,

-A learning monk!

Replies are listed 'Best First'.
Re: Log Files
by Zaxo (Archbishop) on Jan 02, 2002 at 06:24 UTC

    Sure, open STDIN and STDERR as those files:

    use File::Basename; my $script = basename($0); my $logpath = '/path/to/logs/'; open STDOUT, ">> ${logpath}${script}OUT.log" or die $!; open STDERR, ">> ${logpath}${script}ERR.log" or die $!;
    Hope that helps.

    After Compline,
    Zaxo

(shockme) Re: Log Files
by shockme (Chaplain) on Jan 02, 2002 at 06:17 UTC
    If I understand what you're wanting, there are many log file type modules on CPAN. I think you might be interested in Log::Agent or possibly Log::LogLite.

    If things get any worse, I'll have to ask you to stop helping me.

Re: Log Files
by lemming (Priest) on Jan 02, 2002 at 06:23 UTC

    Not the clearest question, but here's a try
    You can reopen STDOUT and STDERR in your perl script so that the output goes to the log files.

    open(STDOUT, ">>stdout.log") or die "horribly";
    After that your default print statements goes to stdout.log. Doing the same with STDERR will cause all your error messages to be sent to the log. You may to turn buffering off for this purpose as well.

Re: Log Files
by talexb (Chancellor) on Jan 02, 2002 at 09:18 UTC
    It sounds like
    foo >foo.out 2>foo.err
    is working fine for you, but for some reason you want to use something else. Is main::logfile a solution in search of a problem?

    What problem are you trying to solve?

    --t. alex

    "Excellent. Release the hounds." -- Monty Burns.