In php, how do you log errors but don't show them to the user

I have the following code to manage error reporting. I am trying to make it possible to bind error logs on our server, but I do not want the page to display errors. I'm not trying to just make mistakes, we don’t have them.

   if (defined('ENVIRONMENT'))
{
    switch (ENVIRONMENT)
    {
        case 'development':
            error_reporting(E_ALL);
        break;

        case 'testing':
        case 'production':
            error_reporting(0);
            ini_set('display_errors', 'Off');

        break;

        default:
            exit('The application environment is not set correctly.');
    }
}
+4
source share
1 answer

Use file log

case 'development':
    error_reporting(E_ALL);
    ini_set('display_errors', 'Off');
    ini_set("log_errors", 1);
    ini_set("error_log", "/tmp/php-error.log");
break;


error_log( "Hello, errors!" );
+5
source

Source: https://habr.com/ru/post/1527021/


All Articles