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.
Post Reply
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

Post by 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: 3911
Joined: Tue Aug 23, 2005 1:56 pm
Location: South coast, UK
Contact:

Re: Joomla causing php error to NOT be logged

Post by 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

Post by 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: 3911
Joined: Tue Aug 23, 2005 1:56 pm
Location: South coast, UK
Contact:

Re: Joomla causing php error to NOT be logged

Post by 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! Master
Joomla! Master
Posts: 11335
Joined: Thu Feb 15, 2007 5:48 am
Location: Suzhou, China

Re: Joomla causing php error to NOT be logged

Post by 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

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

Post by 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! Master
Joomla! Master
Posts: 11335
Joined: Thu Feb 15, 2007 5:48 am
Location: Suzhou, China

Re: Joomla causing php error to NOT be logged

Post by 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

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

Post by 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

Post by 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! Master
Joomla! Master
Posts: 11335
Joined: Thu Feb 15, 2007 5:48 am
Location: Suzhou, China

Re: Joomla causing php error to NOT be logged

Post by 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

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

Post by ihtus » Wed Mar 28, 2018 4:30 pm

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

error_reporting() output is 32767

mbabker
Joomla! Hero
Joomla! Hero
Posts: 2220
Joined: Sun Feb 28, 2010 8:26 pm

Re: Joomla causing php error to NOT be logged

Post by 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.

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 11335
Joined: Thu Feb 15, 2007 5:48 am
Location: Suzhou, China

Re: Joomla causing php error to NOT be logged

Post by 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

mickeifin453
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Sat Oct 13, 2018 7:29 pm

Re: Joomla causing php error to NOT be logged

Post by mickeifin453 » Sat Oct 13, 2018 8:44 pm

Hi ihtus,

think firstly you should update the latest joomla version, after that run the code once again, still if you face the same error then in your Joomla control panel, change the Error Reporting from Maximum back to System Default, after that Locate configuration.php file in the folder, where you installed your Joomla.

jobst
Joomla! Apprentice
Joomla! Apprentice
Posts: 15
Joined: Sun Feb 15, 2009 1:49 am

Re: Joomla causing php error to NOT be logged

Post by jobst » Wed Jul 31, 2019 6:51 am

I have the same problem, no matter what I do the errors do NOT get logged/displayed.
I though nothing was wrong with that site until a form was failing - upon posting/submitting.

The receiving page of the form is using a class, within that class is a function that was deprecated and taken out (fair enough really!) - but I forgot to take it out. I looked in the class file, and sure enough the function is not there anymore. I would expect an error to be found in the php log telling me at least "syntax error".

If I take the function CALL out, all works as expected, if I leave it in the error is silently discarded and execution of the script halts - no error ANY WHERE!
  • 1. I have the correct settings in php.ini - other sites log, a script (exec commandline) containing an error logs
    2. I do not see ANYTHING from the JOOMLA site, even no deprecated warnings, no variable warnings, nothing (this is set in php.ini)
    2. I have set debug system to on (admin pnael)
    3. I have set error reporting to development (admin panel)
    4. I use "error_log('before the error');" just before the missing class function call and it IS LOGGED
    5. I use "error_log('after the error');" just after the missing class function call -> NEVER SHOWS UP
    6. I put a couple of lines BEFORE THE MISSING function using "ini_set(display_errors,1);ini_set(log_errors,1);" and so on, does not help
    7. My version of JOOMLA is 3.9.10.
This means the errors get eaten up - somewhere.
All my other NON JOOMLA sites on the same machine log and show errors.

So I can confirm those issues.


Post Reply

Return to “Joomla! 3.x Coding”