I did a quick search of the forums but it doesn't seem to be what I'm looking for - does anyone know of a way I can output all the errors and warnings from error_reporting(E_ALL); to a file I specify?
[RESOLVED] error_reporting to a file?
it is in the php.ini
you can turn on/off:
1. logging to screen, display
2. logging to your error file
so you can have either, both or none
If you turn on logging to file
you may also config 'path to your error_log file'
It is rather well explained in php.ini, what options are
Of course the error_reporting level will effect this logging.
Remember to Restart your server, if you change php.ini
From my own phpinfo
Loaded Configuration File C:\php\php.ini
display_errors On
error_log c:/phperror/phperr.log
html_errors On
log_errors On
There is a setting in php.ini that does this. See
http://pl.php.net/manual/en/ref.errorfunc.php
Yeah, I know I can change it for the server, but is there a way to do it in just a single script? I was hoping maybe something like error_reporting(E_ALL, 'file.txt'); but I know it's not that simple.
yes, you can change it in your script
http://php.net/manual/en/ini.php#ini.list
PHP_INI_ALL means this variable can be set everywhere
- php.ini, httpd.conf(Apache) .htaccess and in your php scripts
you would use [man]ini_set[/man]
and set
log_errors = 1
error_log = file
<?php
error_reporting( E_ALL );
ini_set('log_errors', '1');
ini_set('error_log', 'path/filename');
?>
or in .htaccess
php_value error_reporting 2047 (same as E_ALL )
php_flag log_errors On
php_value error_log path/filename (I think without quotes around)
Thanks a lot, I'll try that once I get back from class.
Here is another trick
If you want to log errors to a file in same folder where your script is.
In this case a file named: phperror.log
<?php
error_reporting( E_ALL );
ini_set('log_errors', '1');
// dirname of __FILE__ is this directory
ini_set('error_log', dirname(__FILE__).'/_phperror.log');
echo 'hello; // I made an error here = missing quote
?>
That works great, thanks.