干货:yii日志功能详解
来源:互联网 发布:海尔电脑网络驱动 编辑:程序博客网 时间:2024/05/16 12:52
转载请注明来自souldak,微博:@evagle
'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 profilingdefined('YII_DEBUG_PROFILING') or define('YII_DEBUG_PROFILING',true);//trace leveldefined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);//execution timedefined('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日志功能详解
- yii日志功能详解
- yii日志记录功能
- 日志功能--yii::trace()和yii::log()
- Yii 日志 图文详解 [实例]
- 【Yii】日志
- 干货!!!Yii 1.1操作Cookie
- YII相关资料(干货)
- 干货!融云RCE产品上线,具体产品功能详解!
- /var/log/ 日志文件功能详解
- Yii日志模块
- yii之-日志使用
- YII日志记录
- yii 2.0 写入日志
- yii 2.0 写入日志
- yii 2.0 写入日志
- YII中日志
- yii 自定义日志文件
- COJ 1236 STL中的map每日二水
- stm32端口“重映射” &&串口学习
- 2-sat问题总结
- 数字有线机顶盒锁频流程
- Eclipse对Android项目导入、导出、修改工程名详解
- 干货:yii日志功能详解
- StoryBoard使用push跳转不连线。(解决黑屏问题)
- jedis基本介绍(1)
- Write paper:SDN the new norm for network翻译
- sqlite3加密
- struts2文件下载
- http post 方法传递参数的2种方式
- ZOJ:2750 Idiomatic Phrases Game
- DataGridview 获得当前单元格的行号和列号.