codeigniter4 / CodeIgniter4

Open Source PHP Framework (originally from EllisLab)
https://codeigniter.com/
MIT License
5.34k stars 1.9k forks source link

errors and warnings are not shown in log file #5333

Closed John-Betong closed 2 years ago

John-Betong commented 2 years ago

PHP Version

8.0

CodeIgniter4 Version

4.1.5

Which operating systems have you tested for this bug?

Linux

Which server did you use?

apache

Database

MySQL 5.6

What happened?

See nothing using “production” because all errors and warnings blocked with error_reporting(0): set to zero.

Steps to Reproduce

Forced error and nothing showing in log files.

Expected Output

Expected errors and warnings to be shown in log file.

Anything else?

Raised detailed thread on forum with optional testing code and results:

https://forum.codeigniter.com/thread-80546.html

kenjis commented 2 years ago

I can't reproduce. Or am I misunderstand something?

Add error to the controller.

--- a/app/Controllers/Home.php
+++ b/app/Controllers/Home.php
@@ -6,6 +6,6 @@ class Home extends BaseController
 {
     public function index()
     {
-        return view('welcome_message');
+        return view('welcome_message')
     }
 }
$ php spark serve

Navigate http://localhost:8080.

See the log:

CRITICAL - 2021-11-15 19:20:11 --> syntax error, unexpected token "}", expecting ";"
#0 /Users/kenji/work/codeigniter/CodeIgniter4/system/Autoloader/Autoloader.php(241): CodeIgniter\Autoloader\Autoloader->includeFile('/Users/kenji/wo...')
#1 /Users/kenji/work/codeigniter/CodeIgniter4/system/Autoloader/Autoloader.php(219): CodeIgniter\Autoloader\Autoloader->loadInNamespace('App\\Controllers...')
#2 [internal function]: CodeIgniter\Autoloader\Autoloader->loadClass('App\\Controllers...')
#3 /Users/kenji/work/codeigniter/CodeIgniter4/system/CodeIgniter.php(789): class_exists('\\App\\Controller...', true)
#4 /Users/kenji/work/codeigniter/CodeIgniter4/system/CodeIgniter.php(397): CodeIgniter\CodeIgniter->startController()
#5 /Users/kenji/work/codeigniter/CodeIgniter4/system/CodeIgniter.php(318): CodeIgniter\CodeIgniter->handleRequest(NULL, Object(Config\Cache), false)
#6 /Users/kenji/work/codeigniter/CodeIgniter4/public/index.php(37): CodeIgniter\CodeIgniter->run()
#7 /Users/kenji/work/codeigniter/CodeIgniter4/system/Commands/Server/rewrite.php(43): require_once('/Users/kenji/wo...')
#8 {main}
kenjis commented 2 years ago

If you want to see all errors, you have to change the Boot file: https://github.com/codeigniter4/CodeIgniter4/blob/0406780029a8f0e14fedb2eb6ac2aeda7b87f128/app/Config/Boot/production.php#L11

error_reporting(E_ALL);
John-Betong commented 2 years ago

Regret the delay, if I received a notification it was lost among all the other notifications.

I downloaded the latest CI4 Ver: 4.1.5 and noticed that the app/Config/Boot/production.php no longer has error_reporting(0)? I unsuccessfully searched for the Change Log update and could not find it?

Anyway my beef was that Production error_reporting used to be set to ZERO and the suggestion was to use CU_DEBUG to select PHP default error_logging by using the following changes, notified in the forum Request:

https://forum.codeigniter.com/thread-80546.html

I have just tested the following proposal :

system/Debug/Exceptions -> public function initialize()
    {
      if( CI_DEBUG )  {  
        set_exception_handler([$this, 'exceptionHandler']);
        set_error_handler([$this, 'errorHandler']);
        register_shutdown_function([$this, 'shutdownHandler']);
      }//endif;  
    }

A memory saving spin-off of using the above was appreciable:

.env 
  # DEFAULT production
  # CI_ENVIRONMENT = production
    # production  ==> 741,720 bytes - memory_get_usage()   
    # production  ==> 746,424 bytes - memory_get_peak_usage()
  # CI_ENVIRONMENT = development
    # development ==> 831,792 bytes - memory_get_usage()
    # development ==> 836,496 bytes - memory_get_peak_usage()
paulbalandan commented 2 years ago

app/Config/Boot/production.php was never changed with regard to the error_reporting() mask. https://github.com/codeigniter4/CodeIgniter4/blob/8c7f70188e2bb7f19e6c7fcbbadb4dcb94c1cbc7/app/Config/Boot/production.php#L11

So it was never error_reporting(0); to begin with.