干货:yii日志功能详解
Yii 1.1 Application Development Cookbook 这本书很好
components下面增加log配置,如下:
'components' => array(
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'CFileLogRoute',
'levels'=>'trace, info, debug, warn, error, fatal, profile',
'categories'=>'test.*',
'maxFileSize'=>1048576,//单文件最大1G
'logFile'=>'test.log',
),
//
// 开发过程中所有日志直接输出到浏览器了,这样不需要登录服务器看日志了
array(
'class' => 'CWebLogRoute',
'categories' => 'test.*',
'levels' => CLogger::LEVEL_PROFILE,
'showInFireBug' => true,
'ignoreAjaxInFireBug' => true,
),
array(
'class' => 'CWebLogRoute',
'categories' => 'test.* ',
),
array(
'class'=>'CEmailLogRoute',
'levels'=>'error, warning',
'emails'=>'admin@example.com',
),
),
),
),
Yii::beginProfile('blockID');
...code block being profiled...
Yii::endProfile('blockID');
Profiling is especially useful when working with database since SQL executions are often the main performance bottleneck of an application. While we can manually insert beginProfile and endProfile statements at appropriate places to measure the time spent in each SQL execution, Yii provides a more systematic approach to solve this problem.
By setting CDbConnection::enableProfiling to be true in the application configuration, every SQL statement being executed will be profiled. The results can be readily displayed using the aforementioned CProfileLogRoute, which can show us how much time is spent in executing what SQL statement. We can also call CDbConnection::getStats() to retrieve the total number SQL statements executed and their total execution time.
array(
'class'=>'CProfileLogRoute',
'levels' => CLogger::LEVEL_PROFILE,
'showInFireBug' => true,
'ignoreAjaxInFireBug' => true,
'categories' => 'system.db.* ', //只记录db的操作日志,其他的忽略
),
for($i=0;$i<1000;$i++){
$user = UserModel::model()->findByPk("1");//这里只要是数据库操作就行,这个只是个例子
}
'class'=>'CFileLogRoute',
'levels' => CLogger::LEVEL_PROFILE,
'categories' => 'system.db.* ', //只记录db的操作日志,其他的忽略
'logFile'=>'db.log',
),
$yii = dirname(__FILE__).'/../yii/framework/yii.php';
$config = dirname(__FILE__).'/protected/config/main.php'; defined('YII_DEBUG') or define('YII_DEBUG',true); defined('YII_DEBUG_SHOW_PROFILER') or define('YII_DEBUG_SHOW_PROFILER',true);
//enable profiling
defined('YII_DEBUG_PROFILING') or define('YII_DEBUG_PROFILING',true);
//trace level
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);
//execution time
defined('YII_DEBUG_DISPLAY_TIME') or define('YII_DEBUG_DISPLAY_TIME',false);
require_once($yii);
Yii::createWebApplication($config)->run();
2. 在main.php主配置文件里面,的components db 里将enableProfiling设置为true 'components' => array(
'db' => array(
'enableProfiling' => true, //这个是用来记录日志的,会记录每一条语句执行的时间
'enableParamLogging' => true,//true表示包括sql语句的参数在内的信息都会记录到日志里,非常详细
),
)
Yii::log("dfdf",CLogger::LEVEL_INFO,"example");
Yii::log("dfdf",CLogger::LEVEL_ERROR,"example");
Yii::trace("dfdf", "example");
Yii::trace('example trace message', 'example');
Yii::log('info', CLogger::LEVEL_INFO, 'example');
Yii::log('error', CLogger::LEVEL_ERROR, 'example');
Yii::log('trace', CLogger::LEVEL_TRACE, 'example');
Yii::log('warning', CLogger::LEVEL_WARNING, 'example');
Yii::beginProfile('db', 'example');
for($i=0;$i<1000;$i++){
$user = UserModel::model()->findByPk("1");
}
Yii::endProfile('db', 'example');
echo 'done';
干货:yii日志功能详解的更多相关文章
- 关于syslog日志功能详解 事件日志分析、EventLog Analyzer
关于syslog日志功能详解 事件日志分析.EventLog Analyzer 一.日志管理 保障网络安全 Windows系统日志分析 Syslog日志分析 应用程序日志分析 Windows终端服务器 ...
- MySQL日志功能详解
MySQL日志功能详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.查询日志 它是用来保存所有跟查询相关的日志,这种日志类型默认是关闭状态的,因为MySQL的用户有很多,如果 ...
- nginx 日志功能详解
nginx 日志功能 在 nginx 中有两种日志: access_log:访问日志,通过访问日志可以获取用户的IP.请求处理的时间.浏览器信息等 error_log:错误日志,记录了访问出错的信息, ...
- MySQL 日志功能详解
MySQL日志分类 1:查询日志 :query log 2:慢查询日志:slow_query_log 查询执行时长超过指定时长的查询操作所记录日志 3:错误日志:error log ...
- SVN功能详解
SVN功能详解 TortoiseSVN是windows下其中一个非常优秀的SVN客户端工具.通过使用它,我们可以可视化的管理我们的版本库.不过由于它只是一个客户端,所以它不能对版本库进行权限管理. ...
- UIViewController中各方法调用顺序及功能详解
UIViewController中各方法调用顺序及功能详解 UIViewController中loadView, viewDidLoad, viewWillUnload, viewDidUnload, ...
- Fiddler抓取https请求 & Fiddler抓包工具常用功能详解
Fiddler抓取https请求 & Fiddler抓包工具常用功能详解 先来看一个小故事: 小T在测试APP时,打开某个页面展示异常,于是就跑到客户端开发小A那里说:“你这个页面做的有问 ...
- syslog之一:Linux syslog日志系统详解
目录: <syslog之一:Linux syslog日志系统详解> <syslog之二:syslog协议及rsyslog服务全解析> <syslog之三:建立Window ...
- Java中日志组件详解
avalon-logkit Java中日志组件详解 lanhy 发布于 2020-9-1 11:35 224浏览 0收藏 作为开发人员,我相信您对日志记录工具并不陌生. Java还具有功能强大且功能强 ...
随机推荐
- ffmpeg 命令
1.保存文件: ffmpeg -i rtsp://admin:12345@172.29.61.108/Streaming/Channels/1 -vcodec copy -acodec libvo_a ...
- 【BZOJ】【1053】【HAOI2007】反素数ant
搜索 经典搜索题目(其实是蒟蒻只会搜……vfleaking好像有更优秀的做法?) 枚举质数的幂,其实深度没多大……因为$2^32$就超过N了……而且质数不能取的太大,所以不会爆…… /******** ...
- WPF编程学习——布局
本文目录 1.布局简介 2.面板(Panel) 3.视图框(Viewbox) 4.滚动视图控件(ScrollViewer) 5.公共布局属性 1.布局简介 应用程序界面设计中,合理的元素布局至关重要, ...
- Topcoder srm 632 div2
脑洞太大,简单东西就是想复杂,活该一直DIV2; A:水,基本判断A[I]<=A[I-1],ANS++; B:不知道别人怎么做的,我的是100*N*N;没办法想的太多了,忘记是连续的数列 我们枚 ...
- HDU-2604_Queuing
题目:Problem Description Queues and Priority Queues are data structures which are known to most comput ...
- Hadoop发行版本介绍
前言 从2011年开始,中国进入大数据风起云涌的时代,以Hadoop为代表的家族软件,占据了大数据处理的广阔地盘.开源界及厂商,所有数据软件,无一不向Hadoop靠拢.Hadoop也从小众的高富帅领域 ...
- JavaScript事件委托的技术原理
如今的JavaScript技术界里最火热的一项技术应该是‘事件委托(event delegation)’了.使用事件委托技术能让你避免对特定的每个节点添加事件监听器:相反,事件监听器是被添加到它们的父 ...
- javascript (js)中的基本概念
1. 基本数据类型 1.1 number (数字)在js中没有整形和浮点型的区分,所有的数字都是浮点型标识, 采用64位的浮点格式来表示数字.如果数字类型用在字符串连接表达式中,则会自动转换成字符串, ...
- 开源搜索引擎Solr的快速搭建及集成到企业门户最佳实施方案--转载
笔者经过研究查阅solr官方相关资料经过两周的研究实现了毫秒级百万数据的搜索引擎的搭建并引入到企业门户.现将实施心得和步骤分享一下. 1. jdk1.6 安装jdk1.6到系统默认目录下X: ...
- 学生信息管理 --- c语言实现
第一次写比较大的程序,昨晚看了 大话数据结构 有感-----同样求 1+2+3+4+...+100,我则是简单的从1+2+3+4+...+100. 而不是 (1+100) / 2 * 100;(高 ...