How to create Error log in PHP Codeigniter Framework [duplicate]

橙三吉。 提交于 2019-12-24 03:06:48

问题


How to create Error log in PHP Codeigniter Framework? The Error log has Possible to create in localhost ?


回答1:


Yes you can enable for localhost. just go to applications/config/config.php and add

$config['log_threshold'] = 1;
$config['log_path'] = '';// add your path

$config['log_path'] = '' default will be applications/logs dir

log threshold values :-

0 = Disables logging, Error logging TURNED OFF
1 = Error Messages (including PHP errors)
2 = Debug Messages
3 = Informational Messages
4 = All Messages

For more :- How to do error logging in CodeIgniter (PHP)




回答2:


Yes you can enable Error log for both localhost and live server. Please do the step by step procedure as stated bellow:

  1. In application > config > config.php change line 183 to $config['log_threshold'] = 4;
  2. Then run your application and you will get the log file with date as name in applicaiton > logs directory.

If you want to log custom error then use the following syntax:

log_message('level', 'message')

Where level can be Error, Debug, Info etc.




回答3:


PHP has an in built system of logging errors.

This file is php_errors.log

This file's locations:

Ubuntu: /var/log/php_errors.log XAMPP (Windows) : /xampp/php/logs/php_errors.log

To write to this log file, simply call a function 'error_log'.

e.g. to write a string to this file error_log('This is a string');

OR

CodeIgniter has some error logging functions built in.

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.');

To send an email you need to extend the core CI_Exceptions class method log_exceptions(). You can do this yourself or use this. More info on extending the core here

See http://ellislab.com/codeigniter/user-guide/general/errors.html



来源:https://stackoverflow.com/questions/26733033/how-to-create-error-log-in-php-codeigniter-framework

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!