logging - Perl: STDOUT reopened as FH only for input -


i have following error message (with perl 5):

tools.pm: filehandle stdout reopened fh input @ /usr/local/lib/perl5/site_perl/mach/5.20/template/provider.pm line 967.

i understand cause: stdout closed , later same fd used unrelated stdout.

the code right thing. problem error message should not logged.

how stop printing error message our log file?

detailed handling of errors outlined in template::manual::config::error.

it can categorized in constructor specifying templates exception types

my $template = template->new({        errors => {          user     => 'user/index.html',          dbi      => 'error/database',          default  => 'error/default',      }, }); 

which can raised using throw directive

[% throw user.login 'no user id: please login' %]

or calling throw method

$context->throw('user.passwd', 'incorrect password');   $context->throw('incorrect password');    # type 'undef' 

or perl code calling die, perhaps template::exception object.

how use solve problem matter of details, of none provided.

but want find (user) code triggers , clean up. one, noted ikegami in comment, don't close stdout reopen /dev/null. (i'd say, never close stds.) instance, if don't want see stdout more

open stdout, '>', '/dev/null'; 

or first save before reopening can restore later

open $saveout, '>&', 'stdout'; open stdout, '>', '/dev/null'; ... open stdout, '>', $saveout;  # restore stdout close $saveout;              # if unneeded 

(see open), or if feasible create local *foo , use save stdout.

the warning comes because lowest unused file descriptor used , here fd 1 vacated closing stdout, used input isn't ok. why it's not ok , why emit warning, this thread , old bug report useful. goes beyond perl.


one generic way use __warn__ hook

begin {     $sig{__warn__} = sub {         warn @_              unless $_[0] ~= /filehandle stdout reopened fh input/     } }; 

where warning emitted unless matches 1 want suppress. begin block need before use statements modules expected affect. if know scope @ needed better localize it, local $sig{__warn__} = sub {...};

see this post , links, other posts , relevant documentation, more details.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -