Joomla causing php error to NOT be logged

For Joomla! 3.x Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
ihtus
Joomla! Intern
Joomla! Intern
Posts: 66
Joined: Thu Feb 28, 2008 2:30 pm
Location: Canada

Joomla causing php error to NOT be logged

Postby ihtus » Wed Mar 28, 2018 12:22 pm

My setup: OpenSuse Leap 42.2, Apache 2.4.23, PHP 7.0.7, Joomla 3.8.6

When initializing Joomla libraries inside php => that causes php errors to NOT be logged in error file.

Here is the proof:

Code: Select all

define( '_JEXEC', 1 );
define( 'DS', DIRECTORY_SEPARATOR );
define('JPATH_BASE', '/srv/www/htdocs');
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );

// initialize the application
$mainframe = JFactory::getApplication('site');
$mainframe->initialise();

require_once("lib.php");


lib.php

Code: Select all

function test() {
    $var='2',
    echo $var;
}



For the code above, there are no logs in /var/log/apache2/error_log

And if I will comment all Joomla initialization code and leave only require_once("lib.php"); => the error is logged ok

Code: Select all

PHP Parse error:  syntax error, unexpected ',' in ...


Also if I would comment require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' ); => the error would be logged as well..

Code: Select all

define( '_JEXEC', 1 );
define( 'DS', DIRECTORY_SEPARATOR );
define('JPATH_BASE', '/srv/www/htdocs');
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
//require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );

// initialize the application
//$mainframe = JFactory::getApplication('site');
//$mainframe->initialise();

require_once("lib.php");


Any thoughts how to have errors logged properly while having joomla libs initialized? Thanks
Last edited by toivo on Wed Mar 28, 2018 2:00 pm, edited 2 times in total.
Reason: mod note: moved to 3.x Coding

gws
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3311
Joined: Tue Aug 23, 2005 1:56 pm
Location: Kent / Sussex / Surrey border UK
Contact:

Re: Joomla causing php error to NOT be logged

Postby gws » Wed Mar 28, 2018 12:25 pm

I should start by updating to the latest joomla 3.8.6 (your version is vulnerable) and see what happens after that.

ihtus
Joomla! Intern
Joomla! Intern
Posts: 66
Joined: Thu Feb 28, 2008 2:30 pm
Location: Canada

Re: Joomla causing php error to NOT be logged

Postby ihtus » Wed Mar 28, 2018 1:06 pm

gws wrote:I should start by updating to the latest joomla 3.8.6 (your version is vulnerable) and see what happens after that.


Hi gws, thanks for the suggestion. I have upgraded to Joomla 3.8.6 and the issue is still there.. absolutely same behavior... any ideas?

gws
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3311
Joined: Tue Aug 23, 2005 1:56 pm
Location: Kent / Sussex / Surrey border UK
Contact:

Re: Joomla causing php error to NOT be logged

Postby gws » Wed Mar 28, 2018 1:14 pm

Sorry crap at coding.
I expect smarter folks will pick this up for you.

User avatar
toivo
Joomla! Exemplar
Joomla! Exemplar
Posts: 9363
Joined: Thu Feb 15, 2007 5:48 am
Location: Nottingham, UK
Contact:

Re: Joomla causing php error to NOT be logged

Postby toivo » Wed Mar 28, 2018 2:09 pm

ihtus wrote:When initializing Joomla libraries inside php => that causes php errors to NOT be logged in error file.
That can happen only if the variable error_reporting in your Joomla file configuration.php has been set to 'none' or 0. Set it to for example 'maximum' and your script will log an error into the PHP error log.
Toivo Talikka, Global Moderator
my first programs were assembled and run in 16KB :)
troubleshooting smtp and other articles https://talikka.com/joomla

ihtus
Joomla! Intern
Joomla! Intern
Posts: 66
Joined: Thu Feb 28, 2008 2:30 pm
Location: Canada

Re: Joomla causing php error to NOT be logged

Postby ihtus » Wed Mar 28, 2018 2:15 pm

toivo wrote:
ihtus wrote:When initializing Joomla libraries inside php => that causes php errors to NOT be logged in error file.
That can happen only if the variable error_reporting in your Joomla file configuration.php has been set to 'none' or 0. Set it to for example 'maximum' and your script will log an error into the PHP error log.


I tried to set that to maximum, development, default.. that does not help.

Actually I found an explanation here https://joomla.stackexchange.com/questi ... on-message

For Joomla on php7+ non-fatal errors no longer contain the file and line in the error. The trick is to handle the output of these errors in your template's error.php file. Add the file if it doesn't exist.


The guy says you can edit error.php from template folder

Code: Select all

echo "Error Code: " . $this->error->getCode();
echo "<br>";
echo htmlspecialchars($this->error->getMessage(), ENT_QUOTES, 'UTF-8');
echo "<br><br>";
echo $this->renderBacktrace();


That would show file name and line of the error on the web page.. but that won't help to log non-fatal error into php logs...

User avatar
toivo
Joomla! Exemplar
Joomla! Exemplar
Posts: 9363
Joined: Thu Feb 15, 2007 5:48 am
Location: Nottingham, UK
Contact:

Re: Joomla causing php error to NOT be logged

Postby toivo » Wed Mar 28, 2018 2:36 pm

ihtus wrote:I tried to set that to maximum, development, default.. that does not help.
Try again. That is how Joomla sets the error handling when the framework is bootstrapped in CLI scripts. If it does not work, the problem is somewhere else.

The post at joomla.stackexchange.com and the code you copied are not relevant because you have a stand-alone PHP CLI script, not a Joomla template.
Toivo Talikka, Global Moderator
my first programs were assembled and run in 16KB :)
troubleshooting smtp and other articles https://talikka.com/joomla

ihtus
Joomla! Intern
Joomla! Intern
Posts: 66
Joined: Thu Feb 28, 2008 2:30 pm
Location: Canada

Re: Joomla causing php error to NOT be logged

Postby ihtus » Wed Mar 28, 2018 3:15 pm

toivo wrote:Try again. That is how Joomla sets the error handling when the framework is bootstrapped in CLI scripts. If it does not work, the problem is somewhere else.

The post at joomla.stackexchange.com and the code you copied are not relevant because you have a stand-alone PHP CLI script, not a Joomla template.


Tried.. that does not help...

Well.. the error.php overriding is relevant

before editing error.php, if I load the page into browser =>

Code: Select all

Error: 0
syntax error, unexpected ','


After editing error.php:

Code: Select all

Error Code: 0
syntax error, unexpected ','

Call stack
#    Function    Location
1    ()    JROOT/cgi_appsrv/hr/hr_lib.php:541

ihtus
Joomla! Intern
Joomla! Intern
Posts: 66
Joined: Thu Feb 28, 2008 2:30 pm
Location: Canada

Re: Joomla causing php error to NOT be logged

Postby ihtus » Wed Mar 28, 2018 3:54 pm

UPDATE:
Wiped the current joomla from my dev server. Installed a brand new one, Joomla 3.8.6, with no 3rd party extensions.
Joomla Global Config: Error reporting set to Maximum.

The scenario is exactly same as in my first post...

That means no 3rd party extensions are causing the error logging problem...

Is there any other setting to change to solve that? Or even maybe core code change?

User avatar
toivo
Joomla! Exemplar
Joomla! Exemplar
Posts: 9363
Joined: Thu Feb 15, 2007 5:48 am
Location: Nottingham, UK
Contact:

Re: Joomla causing php error to NOT be logged

Postby toivo » Wed Mar 28, 2018 4:22 pm

ihtus wrote:That means no 3rd party extensions are causing the error logging problem...
The will not cause any issues because your CLI script does not load any extensions.

Use the following statement to display the value of error_reporting at different stages:

Code: Select all

echo 'error_reporting = ' . error_reporting() . PHP_EOL;

ihtus wrote:Is there any other setting to change to solve that?
Does your php.ini set the location of PHP error file? You can check it from Joomla's System - PHP Information,but here are the relevant settings in php.ini:

Code: Select all

log_errors = On
error_log = "the full path to the error log file"
Toivo Talikka, Global Moderator
my first programs were assembled and run in 16KB :)
troubleshooting smtp and other articles https://talikka.com/joomla

ihtus
Joomla! Intern
Joomla! Intern
Posts: 66
Joined: Thu Feb 28, 2008 2:30 pm
Location: Canada

Re: Joomla causing php error to NOT be logged

Postby ihtus » Wed Mar 28, 2018 4:30 pm

error_log is set to /var/log/apache2/error_log

error_reporting() output is 32767

User avatar
mbabker
Joomla! Hero
Joomla! Hero
Posts: 2148
Joined: Sun Feb 28, 2010 8:26 pm
Location: White Bear Lake, MN, USA
Contact:

Re: Joomla causing php error to NOT be logged

Postby mbabker » Wed Mar 28, 2018 5:38 pm

Since Joomla 3.5, when PHP 7 compatibility was included in a stable release, Joomla's global uncaught exception handler also catches anything implementing the PHP 7 "Throwable" interface. Between PHP 5 and PHP 7 a lot of errors were converted from non-catchable errors to catchable Throwable implementations. Our exception handler doesn't do anything to write to PHP's error log file, we do try to write a log message using Joomla's logging API though.

If I'm not mistaken syntax errors are one of the error types converted to a Throwable. So that'd be why those messages aren't getting to the system log.

Maybe we need another hook point in the bootup process similar to the optional defines.php file that could let someone add a file with (as an example) an instruction to tell our logging API to write certain messages to PHP's error log without having to rely on the system booting up far enough for a plugin to be able to add loggers.
Release Lead, CMS Maintainer, Framework Maintainer, Security Team Member, .org System Administrator

Manually updating Joomla? See https://gist.github.com/mbabker/d7bfb4e1e2fbc6b7815a733607f89281

User avatar
toivo
Joomla! Exemplar
Joomla! Exemplar
Posts: 9363
Joined: Thu Feb 15, 2007 5:48 am
Location: Nottingham, UK
Contact:

Re: Joomla causing php error to NOT be logged

Postby toivo » Wed Mar 28, 2018 6:13 pm

Thanks, Mike! That is an interesting change in the behaviour and handling of PHP errors between PHP 5 and PHP 7: http://php.net/manual/en/language.errors.php7.php

However, PHP syntax errors are usually ironed out in PHP editor applications before any Joomla extensions or CLI scripts reach the live production environment. It would still be important to include entries in the PHP error log, if a script happens to get corrupted or modified by hackers.
Toivo Talikka, Global Moderator
my first programs were assembled and run in 16KB :)
troubleshooting smtp and other articles https://talikka.com/joomla


Return to “Joomla! 3.x Coding”

Who is online

Users browsing this forum: SharkyKZ and 3 guests