5

i want to create the error logs but not to display it in browser.

Currently when an error or warning/notice is occurs, then logs is created and error is displayed to the browser but i want to force the system to not show the error message in browser to the site visitor but create the logs for me.

Thanks

user2223377
  • 73
  • 1
  • 11

4 Answers4

7

Make sure you have something like this in your php.ini:

display_errors = Off
error_log = /var/log/php/error.log # Assuming you have /var/log/php directory and it's writable by httpd
error_reporting = E_ALL & ~E_DEPRECATED

Or set them as run-time options with ini_set()

Roman Newaza
  • 11,405
  • 11
  • 58
  • 89
  • I uses `ini_set()` but still cannot logs the errors without showing it on browser. I also cannot log the error to other custom file – Citra45Abadi Apr 10 '17 at 03:19
6

Add this to the top of your script:

//don't display errors
ini_set('display_errors', 0);
//write errors to log
ini_set('log_errors', 1);
//error log file name
ini_set('log_errors', '/var/log/php/error.log');

error_reporting(E_ALL);
user4035
  • 22,508
  • 11
  • 59
  • 94
0

May be try

error_reporting(E_ERROR | E_PARSE);
chandresh_cool
  • 11,753
  • 3
  • 30
  • 45
0

If you want log custom errors:

try {
    // your code here
} catch (Exception $e){
    error_log($e->getMessage(), $e->getCode(), $e->getFile().' Line '.$e->getLine());
}

else use user4035 way.

Community
  • 1
  • 1
maximkou
  • 5,252
  • 1
  • 20
  • 41