Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^6: Why can't I write to a custom log from a Catalyst application on SELinux/CentOS

by LanX (Saint)
on Feb 12, 2021 at 01:26 UTC ( [id://11128284]=note: print w/replies, xml ) Need Help??


in reply to Re^5: Why can't I write to a custom log from a Catalyst application on SELinux/CentOS
in thread Why can't I write to a custom log from a Catalyst application on SELinux/CentOS

even easier is using method autoflush directly.

Got it from HaukeX' recent post.

I should have read the FAQ: https://perldoc.perl.org/perlfaq5#How-do-I-flush/unbuffer-an-output-filehandle?-Why-must-I-do-this? more carefully :)

#!/usr/bin/perl use strict; use warnings; use feature qw{ say }; unlink "./log.txt" or warn "$!"; open OUT, '>>', 'log.txt' or die $!; if (0){ # as you like my $previous_default = select(OUT); # save previous default $|++; # autoflush OUT select($previous_default); # restore previous default } else { #use PerlIO; # needed for Perl <5.14 OUT->autoflush(); } print OUT "before close"; open IN, '<', 'log.txt' or die $!; my $read; $read = <IN>; chomp $read; say "Before close: <$read>"; close OUT;

-*- mode: compilation; default-directory: "d:/tmp/pm/" -*- Compilation started at Fri Feb 12 02:23:56 C:/Perl_524/bin\perl.exe -w d:/tmp/pm/auto_flush.pl Before close: <before close> Compilation finished at Fri Feb 12 02:23:56

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11128284]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-20 00:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found