阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

PHP CI(CodeIgniter)log级别设置

205次阅读
没有评论

共计 3025 个字符,预计需要花费 8 分钟才能阅读完成。

1、Ci 的报错级别设置一般在 index.php 中,可以设置 ENVIRONMENT。一般来讲,开发的时候选择 development 模式,正式发布之后,选择 production 模式。

代码如下:

/*
 *—————————————————————
 * APPLICATION ENVIRONMENT
 *—————————————————————
 *
 * You can load different configurations depending on your
 * current environment. Setting the environment also influences
 * things like logging and error reporting.
 *
 * This can be set to anything, but default usage is:
 *
 *    development
 *    testing
 *    production
 *
 * NOTE: If you change these, also change the error_reporting() code below
 *
 */
 define(‘ENVIRONMENT’, ‘development’);
/*
 *—————————————————————
 * ERROR REPORTING
 *—————————————————————
 *
 * Different environments will require different levels of error reporting.
 * By default development will show errors but testing and live will hide them.
 */

if (defined(‘ENVIRONMENT’))
{
 switch (ENVIRONMENT)
 {
  case ‘development’:
   error_reporting(E_ALL);
  break;
 
  case ‘testing’:
  case ‘production’:
   error_reporting(0);
  break;

  default:
   exit(‘The application environment is not set correctly.’);
 }
}

2、CI 的错误日志默认存放在 application/logs/log-[time].php 中,日志的级别、路径、时间格式等,在 application/config/config.php 文件中设置,相关代码如下:

/*
|————————————————————————–
| Error Logging Threshold
|————————————————————————–
|
| If you have enabled error logging, you can set an error threshold to
| determine what gets logged. Threshold options are:
| You can enable error logging by setting a threshold over zero. The
| threshold determines what gets logged. Threshold options are:
|
| 0 = Disables logging, Error logging TURNED OFF
| 1 = Error Messages (including PHP errors)
| 2 = Debug Messages
| 3 = Informational Messages
| 4 = All Messages
|
| For a live site you’ll usually only enable Errors (1) to be logged otherwise
| your log files will fill up very fast.
|
*/
$config[‘log_threshold’] = 0;

/*
|————————————————————————–
| Error Logging Directory Path
|————————————————————————–
|
| Leave this BLANK unless you would like to set something other than the default
| application/logs/ folder. Use a full server path with trailing slash.
|
*/
$config[‘log_path’] = ”;

/*
|————————————————————————–
| Date Format for Logs
|————————————————————————–
|
| Each item that is logged has an associated date. You can use PHP date
| codes to set your own date formatting
|
*/
$config[‘log_date_format’] = ‘Y-m-d H:i:s’;

3、在自己写代码需要记录日志时,可以调用全局函数 log_message(‘ 级别 ’,’ 消息 ’),级别的参数为 (调试 debug, 错误 error, 信息 info),内容自己定义即可。

log_message(‘error’, ‘error message.’);
log_message(‘debug’, ‘debug message.’);
log_message(‘info’, ‘info message.’); 

CentOS 6.3 安装 LNMP (PHP 5.4,MyySQL5.6) http://www.linuxidc.com/Linux/2013-04/82069.htm

在部署 LNMP 的时候遇到 Nginx 启动失败的 2 个问题 http://www.linuxidc.com/Linux/2013-03/81120.htm

Ubuntu 安装 Nginx php5-fpm MySQL(LNMP 环境搭建) http://www.linuxidc.com/Linux/2012-10/72458.htm

《细说 PHP》高清扫描 PDF+ 光盘源码 + 全套教学视频 http://www.linuxidc.com/Linux/2014-03/97536.htm

PHP 的详细介绍 :请点这里
PHP 的下载地址 :请点这里

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-20发表,共计3025字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中