1 2 3 4 5 6
sub PRINT { my $self = shift; local STDERR; untie STDERR; print STDERR @_; print $my_log_file @_; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
use vars qw( $log_file ); $log_file = "T:/err.log"; package TeeStderr; use Fcntl qw(:flock); sub TIEHANDLE { my $i; bless \$i, shift } sub PRINT { my $r = shift; print "STDERR $$ ", @_; if ( open my $FH, '>>', $log_file ) { flock $FH, LOCK_EX; print $FH "" . localtime, "\t", "ErrorLog: ", "", $$, " ", @_; close $FH; } } package main; $| = 1; tie *STDERR, "TeeStderr";
print "STDERR $$ ", @_;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
package TeeStdErr; use Fcntl qw(:flock); my $log_file = "$ENV{DOCUMENT_ROOT}/state/err.log"; sub TIEHANDLE { my $i; bless \$i, shift } sub PRINT { my $r = shift; local *STDERR; untie *STDERR; print STDERR @_; if ( open my $FH, '>>', $log_file ) { flock $FH, LOCK_EX; print $FH "" . localtime, "\t", "ErrorLog: ", @_; close $FH; } else { warn "Open $log_file '$!'", @_; } } package main; $| = 1; # Tee für STDERR tie *STDERR, "TeeStdErr";
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
use strict; use warnings; package TeeStdErr; use Fcntl qw(:flock); my $log_file = "$ENV{DOCUMENT_ROOT}/state/err.log"; open (my $orig_stderr, '>&', \*STDERR); sub TIEHANDLE { my $i; bless \$i, shift } sub PRINT { my $r = shift; print $orig_stderr @_; if ( open my $FH, '>>', $log_file ) { flock $FH, LOCK_EX; print $FH "" . localtime, "\t", "ErrorLog: ", @_; close $FH; } else { warn "Open $log_file '$!'", @_; } } package main; $| = 1; # Tee für STDERR tie *STDERR, "TeeStdErr"; print STDERR "print STDERR\n"; warn "warn";