现在的位置: 首页 > 综合 > 正文

CI中的LOG和错误处理小结

2013年08月30日 ⁄ 综合 ⁄ 共 1166字 ⁄ 字号 评论关闭
在CI中,对于错误处理和LOG的处理方法,下面小结下:

1 默认在index.php 中,error的级别是ALL,把所有信息都设置出来的

   error_reporting(E_ALL);

可以把其改成E_ERROR级别

2 设置LOG,LOG在application/config下设置

  $config['log_threshold'] = 0;

/*

|--------------------------------------------------------------------------

| Error Logging Directory Path

|--------------------------------------------------------------------------

|

| Leave this BLANK unless you would like to set something other than the default

| system/logs/ folder.  Use a full server path with trailing slash.

|

*/

$config['log_path'] = '';

  0-关闭

  1 – ERROR

   记录所有的错误信息了,连HTML的404错误,和用户端定义的错误

  2-DEBUG

  3-INO:这个级别输出ERROR和DEBUG级别的,都一起了

  4 ALL-MESSAGE:输出所有信息了

$config['log_path'] = ”

如果您不想使用默认的错误日志记录目录配置(system/logs/),可以设置完整的服务器目录。

$config['log_date_format'] = ‘Y-m-d H:i:s’

codeigniter 错误日志时间格式

log_message('级别', '消息')

这个函数可以让你将消息写入记录文件中。你必须在第一个参数中选择三个“级别“中的任何一个, 指明它是那一类消息(调试 debug, 错误 error, 信息info)。 第二个参数是消息本身。 例如:

if ($some_var == "")

{

     log_message('error', 'Some variable did not contain a value.');

}

else

{

     log_message('debug', 'Some variable was correctly set');

}

log_message('info', 'The purpose of some variable is to provide some value.');

而默认的错误定制页在:application/errors/error_general.php和

application/errors/error_404.php 中

可以利用show_error和show_404() 去显示错误信息

  

抱歉!评论已关闭.