-
Notifications
You must be signed in to change notification settings - Fork 2k
Description
PHP Version
8.0
CodeIgniter4 Version
4.1.8
CodeIgniter4 Installation Method
Composer (using codeigniter4/appstarter)
Which operating systems have you tested for this bug?
Windows
Which server did you use?
apache
Database
No response
What happened?
Sort of a bug, sort of a feature request.
In some cases Exception trace doesn't include any useful information.
In CodeIgniter\Debug\Exceptions::exceptionHandler() the log_message() function is called as follows:
log_message('critical', $exception->getMessage() . "\n{trace}", [
'trace' => $exception->getTraceAsString(),
]);
It would be helpful to include the file and line in the message.
Steps to Reproduce
Create a controller method and put the following lines:
set_time_limit(2);
sleep(5);
Expected Output
The log file produces:
CRITICAL - 2022-02-10 14:28:06 --> Maximum execution time of 2 seconds exceeded
#0 [internal function]: CodeIgniter\Debug\Exceptions->shutdownHandler()
#1 {main}
This isn't helpful to know where the timeout is occurring.
Anything else?
By changing the CodeIgniter\Debug\Exceptions::exceptionHandler() log_message() function to include file and line:
log_message('critical', $exception->getMessage().' called in '.$this->cleanPath($exception->getFile()).' line '.$exception->getLine() . "\n{trace}", [
'trace' => $exception->getTraceAsString(),
]);
We now get useful information to where the problem is.
CRITICAL - 2022-02-10 14:29:05 --> Maximum execution time of 2 seconds exceeded called in APPPATH\Controllers\Admin\Test.php line 14
#0 [internal function]: CodeIgniter\Debug\Exceptions->shutdownHandler()
#1 {main}
Perhaps there is a better way to do this.. maybe even a configurable option to turn this on?