STDERR Redirection and Recovery in Dancer

When starting my, http serverI do not want to see >> Dancer2 v0.201000 server <pid> listening on http://0.0.0.0:<port>printed on stderr. This is why I added the following line before callingstart()

get "/pwd" => sub {
    my $pwd = cwd;
    print STDERR "\n\n[PWD] : $pwd\n"; # this line is not being printed
    print "\n\n[STDOUT::PWD] : $pwd\n";
    my %responseHash = ( pwd => $pwd );
    my $response = encode_json \%responseHash;
    return $response;
};    

my $dancerStartErr;

sub startServer {
    open (local *STDERR, ">", \$dancerStartErr) 
        or die "Dup err to variable error: $!\n";

    start();
}

startServer();

The problem is that later I can not print something on STERR. How can I reopen stderr( open(STDERR, ">", \*STDERR);doesn't help)?

+4
source share
2 answers

, -, , Dancer2:: Logger:: Null. , config.yml . , producion, # appdir/environment/production.yml.

logger: 'null'

'console', .

Dancer2:: Logger:: Dancer2 CPAN . . , , Dancer2::Core::Role::Logger.

, , STDERR , .

print STDERR "\n\n[PWD] : $pwd\n"; # this line is not being printed

, , . Dancer2 .

  • core
  • debug
  • info
  • warning
  • error

. Dancer2:: Manual.

, , , , debug.

debug "[PWD] : $pwd";

. ..

+2

select ,

my $oldfh = select(STDERR);

select($oldfh);

:

0

Source: https://habr.com/ru/post/1655040/


All Articles