Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write to error log file in PHP [closed]

Tags:

php

reference

I want to write a message to an error log file when executing PHP code.

I am trying to use the PHP error_log() function Docs.

But it's not working properly for me.

like image 817
Vasant Avatar asked Mar 20 '13 17:03

Vasant


People also ask

How can we log error messages to a file in PHP?

The ini_set(“log_errors”, TRUE) command can be added to the php script to enable error logging in php. The ini_set('error_log', $log_file) command can be added to the php script to set the error logging file. Further error_log($error_message) function call can be used to log error message to the given file.

How do I enable PHP error logging?

Enable Error Logging in php. If you want to enable PHP error logging in individual files, add this code at the top of the PHP file. ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); Now, you must enable only one statement to parse the log errors in the php.

How can we log error messages to an email in PHP?

PHP error_log() Function The error_log() function sends an error message to a log, to a file, or to a mail account.

How do I log all errors in PHP?

Quickly Show All PHP Errors The quickest way to display all php errors and warnings is to add these lines to your PHP code file: ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);


1 Answers

If you don't want to change anything in your php.ini file, according to PHP documentation, you can do this.

error_log("Error message\n", 3, "/mypath/php.log"); 

The first parameter is the string to be sent to the log. The second parameter 3 means expect a file destination. The third parameter is the log file path.

like image 91
suspectus Avatar answered Sep 28 '22 04:09

suspectus