YII Debugging Entries

In many cases, Xdebug not suitable for debugging, as it includes clicks to execute a specific line of code. I want to use something similar to the cakePHP debug function for developers to output the value of a specific class property to the browser.

I am using the Yii framework and this is my configuration for yii log in main.php :

 'log'=>array( 'class'=>'CLogRouter', 'routes'=>array( array( 'class'=>'CFileLogRoute', 'levels'=>'trace, info, error, warning, vardump', ), array( 'class'=>'CWebLogRoute', 'enabled' => YII_DEBUG, 'levels'=>'error, warning, trace, log, vardump', 'showInFireBug'=>true, ), ), ), 

In one of my specific controllers, I am testing this code:

 Yii::log("CallFromUserController",'info', 'application'); 

However, I do not see this being printed in firebug. I used Chris's example:

http://chris-backhouse.com/advanced-logging-in-yii/775

+6
source share
3 answers

I finally managed to find a solution:

In my main.php, I did this:

 'log' => array( 'class' => 'CLogRouter', 'routes' => array( array( 'class' => 'CFileLogRoute', 'levels' => 'trace, info, error, warning, vardump', ), // uncomment the following to show log messages on web pages array( 'class' => 'CWebLogRoute', 'enabled' => YII_DEBUG, 'levels' => 'error, warning, trace, notice', 'categories' => 'application', 'showInFireBug' => false, ), ), ), 

In my controller, I used this code:

 $a = new array(1,2,3); Yii::trace(CVarDumper::dumpAsString($a)); 

The application log is shown below on each page.

+10
source

In Yii2

 Yii::trace(VarDumper::dumpAsString($array)); 

The following is an example of a custom log class.

 <?php namespace app\helpers; use Yii; use yii\helpers\VarDumper; class Log { const LOG_CATEGORY_NAME = 'myLog'; public static function e($msg, $data) { if (isset($data)) { $msg .= " " . VarDumper::dumpAsString($data); } Yii::error($msg, self::LOG_CATEGORY_NAME); } } 

Example:

  Log.e("Copying the Estimate data failed. Model::getError(): ", $model->getErrors()); 
+1
source

You must add the following lines to the protected / main.php file for debug mode: true. Trust work like a charm!

 return array( 'preload' => array( 'debug', ), 'components' => array( 'debug' => array( 'class' => 'ext.yii2-debug.Yii2Debug', ), 'db' => array( 'enableProfiling' => true, 'enableParamLogging' => true, ), ), ); 
+1
source

Source: https://habr.com/ru/post/950318/


All Articles