【发布时间】:2014-12-31 05:14:36
【问题描述】:
如何在 PHP Codeigniter 框架中创建错误日志? 错误日志有可能在 localhost 中创建?
【问题讨论】:
标签: php codeigniter
如何在 PHP Codeigniter 框架中创建错误日志? 错误日志有可能在 localhost 中创建?
【问题讨论】:
标签: php codeigniter
是的,您可以为 localhost 启用。只需转到applications/config/config.php 并添加
$config['log_threshold'] = 1;
$config['log_path'] = '';// add your path
$config['log_path'] = '' 默认为应用程序/日志目录
记录阈值:-
0 = Disables logging, Error logging TURNED OFF
1 = Error Messages (including PHP errors)
2 = Debug Messages
3 = Informational Messages
4 = All Messages
【讨论】:
是的,您可以为本地主机和实时服务器启用错误日志。请按照以下说明逐步进行:
$config['log_threshold'] = 4;
如果要记录自定义错误,请使用以下语法:
log_message('level', 'message')
其中level 可以是错误、调试、信息等。
【讨论】:
PHP 有一个内置的错误记录系统。
这个文件是php_errors.log
此文件的位置:
Ubuntu:/var/log/php_errors.log
XAMPP (Windows) : /xampp/php/logs/php_errors.log
要写入此日志文件,只需调用函数“error_log”。
例如将字符串写入此文件error_log('This is a string');
或
CodeIgniter 内置了一些错误记录功能。
Make your /application/logs folder writable
In /application/config/config.php set
$config['log_threshold'] = 1;
or use a higher number, depending on how much detail you want in your logs
Use log_message('error', 'Some variable did not contain a value.');
要发送电子邮件,您需要扩展核心 CI_Exceptions class method log_exceptions()。您可以自己执行此操作或使用此操作。更多关于在这里扩展核心的信息
见http://ellislab.com/codeigniter/user-guide/general/errors.html
【讨论】: