Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

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

by Cody Fendant (Hermit)
on Feb 11, 2021 at 02:26 UTC ( #11128209=perlquestion: print w/replies, xml ) Need Help??

Cody Fendant has asked for the wisdom of the Perl Monks concerning the following question:

So I'm trying to log what's happening in a certain subroutine in a certain module.

The module and sub definitely are being called because if I add die() to it, the system dies at the right point.

I'm probably trying to do something naive but I'm adding this to the module:

open(LOG,'>>','/var/log/customl.log') or die "can't open log";

To the module (in a BEGIN block or by itself), and it doesn't die, but it doesn't print anything to that log.

Then I put something like this in the key subroutine:

print LOG "Config is $config" or die $!;

And again, it doesn't die but it doesn't print.

I know this idea is probably very blunt force but there's no built-in logger for this system and I need to know what's happening in a complex web app.

Is it because this is on CentOS and it has extra security contexts which prevent me writing to that file? In that case, why doesn't it die? And how can I make it writeable? It can be anywhere, it doesn't have to be in /var/log

Thanks in advance

Replies are listed 'Best First'.
Re: Why can't I write to a custom log from a Catalyst application on SELinux/CentOS
by choroba (Cardinal) on Feb 11, 2021 at 15:46 UTC
    Did you
    close LOG;
    somehwere later, too? If not and the program is still running, the contents might still be waiting in the buffer.
    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
      > close LOG;

      Hm ... I already mentioned $|

      https://perldoc.perl.org/perlvar#$OUTPUT_AUTOFLUSH

      Though the documentation says

      > forces a flush right away and after every write or print on the currently selected output channel.

      so, this means one has to select LOG before using it???

      IO::Handle mentions a method autoflush

      BUT from my experience are opened handles per default unbuffered???

      Or are they only line-buffered, and the OP forgot the trailing "\n"?

      ) and after some digging I found this in the FAQ

      { my $previous_default = select(STDOUT); # save previous default $|++; # autoflush STDOUT select(STDERR); $|++; # autoflush STDERR, to be +sure select($previous_default); # restore previous default }

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

        > Or are they only line-buffered, and the OP forgot the trailing "\n"?

        Nope, from testing in the debugger, do new handles automatically autoflush

        DB<280> open LOG, ">>", "log.txt" DB<281> ! type log.txt DB<282> print LOG "bla" DB<283> ! type log.txt bla DB<284> DB<284> print LOG "\n" DB<285> ! type log.txt bla DB<286>

        probably is Catalyst bending the defaults?

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

Re: Why can't I write to a custom log from a Catalyst application on SELinux/CentOS
by Fletch (Bishop) on Feb 11, 2021 at 16:57 UTC

    Another nitpick: not that it's dying but were it to you didn't include $! in the error message so you won't have any further insight into why the open failed . . .

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re: Why can't I write to a custom log from a Catalyst application on SELinux/CentOS
by LanX (Sage) on Feb 11, 2021 at 02:41 UTC
    Some guesses which might help you:

    • did you deactivate buffering via $| ?
    • did you try another log-file/path?
    • did you try another handle, LOG could have a naming conflict
    • you said you can make it die, but do you also see the die-message then?

    Maybe try to narrow down the cause.

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

Re: Why can't I write to a custom log from a Catalyst application on SELinux/CentOS
by kschwab (Vicar) on Feb 11, 2021 at 14:31 UTC

    Does the file get created if you remove it before running the script?

    Maybe run dmesg after running the script to see if it's some SELinux thing? Or create the file in /tmp instead of /var/log?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2022-12-03 14:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?