You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Bartlomiej Frackiewicz <fr...@inity.de> on 2002/07/15 17:17:35 UTC

Try to tie STDERR

Hi,

sorry for my offtopic posting but i haven't found a general perl mailinglist (with some traffic).

i want to spy my mod_perl/batch programs, in some case they write an error to STDERR i want to send an email to me.

So i wrote Log.pm which has tie functions for handlers, but this doesnt work. it seems that perl don´t use print/printf/write functions for writing to STDERR. can someone point me to the right way?

Here is a piece of code to understand my idea:

#!/usr/bin/perl -w
use Log;

tie (*STDERR, 'Log');
if (0) {
  $w = 'lala';
}
print $w;
untie (*STDERR);

next we have Log.pm which has currently no email functions

#!/usr/bin/perl -w
package Log;

sub TIEHANDLE {
  my $package = shift;
  print "tiehandle called\n";

  return bless {}, $package;
}

sub WRITE {
  my $r = shift;
  print STDOUT "write\n";
}

sub PRINT {
  my $r = shift;
  print STDOUT "print\n";
}

sub PRINTF {
  my $r = shift;
  print STDOUT "printf\n";
}

1;


-- 
BARTLOMIEJ M. FRACKIEWICZ
systementwickler
inity - agentur fuer neue medien gmbh 
birkenstrasse 71                              
40233 duesseldorf

telefon: 0211-99199-0
fax: 0211-99199-10
e-mail: frackiewicz@inity.de


Re: Try to tie STDERR

Posted by Honza Pazdziora <ad...@informatics.muni.cz>.
On Mon, Jul 15, 2002 at 05:17:35PM +0200, Bartlomiej Frackiewicz wrote:
> 
> sorry for my offtopic posting but i haven't found a general perl mailinglist (with some traffic).
> 
> i want to spy my mod_perl/batch programs, in some case they write an error to STDERR i want to send an email to me.

You can check Tie::STDERR, it's available on any good CPAN mirror.
We've been using it (or its newer versions) for a couple of years.
Making the tied filehandle work in mod_perl requires also working with
cleanup handlers, otherwise you will not get the emails as you expect.

If the version of Tie::STDERR on CPAN doesn't work for you, write me,
I might find some time to make distribution from the code we use here.
Of course, YMMV, so you might only use the code as an inspiration.

Yours,

-- 
------------------------------------------------------------------------
 Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
      ... all of these signs saying sorry but we're closed ...
------------------------------------------------------------------------

Re: Try to tie STDERR

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

Bartlomiej Frackiewicz wrote:

> Hi,
> 
> sorry for my offtopic posting but i haven't found a general perl mailinglist (with some traffic).
> 
> i want to spy my mod_perl/batch programs, in some case they write an error to STDERR i want to send an email to me.
> 
> So i wrote Log.pm which has tie functions for handlers, but this doesnt work. it seems that perl don´t use print/printf/write functions for writing to STDERR. can someone point me to the right way?



try taking a look at recipes 6.10 and 16.6 in the mod_perl developer's 
cookbook - 6.10 ties STDERR just as you do.  16.6 is available online 
and explainswhy just tie()ing STDERR doesn't capture all possible 
sources of writes to the error_log.

http://www.modperlcookbook.org/chapters/ch16.pdf

HTH

--Geoff





> 
> Here is a piece of code to understand my idea:
> 
> #!/usr/bin/perl -w
> use Log;
> 
> tie (*STDERR, 'Log');
> if (0) {
>   $w = 'lala';
> }
> print $w;
> untie (*STDERR);
> 
> next we have Log.pm which has currently no email functions
> 
> #!/usr/bin/perl -w
> package Log;
> 
> sub TIEHANDLE {
>   my $package = shift;
>   print "tiehandle called\n";
> 
>   return bless {}, $package;
> }
> 
> sub WRITE {
>   my $r = shift;
>   print STDOUT "write\n";
> }
> 
> sub PRINT {
>   my $r = shift;
>   print STDOUT "print\n";
> }
> 
> sub PRINTF {
>   my $r = shift;
>   print STDOUT "printf\n";
> }
> 
> 1;
> 
> 
>