Skip to content

Instantly share code, notes, and snippets.

@azazqadir
Created August 27, 2019 06:38
Show Gist options
  • Save azazqadir/b24960a637cd094a5a7c1c8881be926b to your computer and use it in GitHub Desktop.
Save azazqadir/b24960a637cd094a5a7c1c8881be926b to your computer and use it in GitHub Desktop.
Commands used in error logging in PHP

To enable error logging, open php.ini file and add this

error_reporting = E_ALL & ~E_NOTICE

error_reporting = E_ALL & ~E_NOTICE | E_STRICT

error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ER… _ERROR

error_reporting = E_ALL & ~E_NOTICE

For logging in individual file, add this in the file

ini_set('display_errors', 1);

ini_set('display_startup_errors', 1);

error_reporting(E_ALL);

Add this statement in php.ini file to enable it

display_errors = on

Additional error logging commands


// Turn off all error reporting

error_reporting(0);

// Report simple running errors

error_reporting(E_ERROR | E_WARNING | E_PARSE);

// Reporting E_NOTICE can be good too (to report uninitialized variables or catch variable name misspellings ...)

error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

// Report all errors except E_NOTICE

error_reporting(E_ALL & ~E_NOTICE);

// Report all PHP errors (see changelog)

error_reporting(E_ALL);

// Report all PHP errors

error_reporting(-1);

// Same as error_reporting(E_ALL);

ini_set('error_reporting', E_ALL);

To check PHP error log location, use this command: <?php phpinfo(); ?>

To store logs in a different file than default one, add this to php.ini error_log = /var/log/php-scripts.log

Source: PHP error logging commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment