Disabling CWebLogRoute inside controller action.

Hi,

I would like to disable CWebLogRoute inside any controller action.

For example, if the action is an Ajax call, do not print out the web logs.

I searched the forums and the only solution seems to involve looking through the entire LogRoutes array, which doesn’t seem very clean.

Is there any thing like:

$this->disableWebLogRoute();

or

Yii::app()->getWebLogRoute()->enabled(false);

Thanks

I had the same problem. I put this method in my base controller class:




	/**

	 * Render JSON data for ajax

	 * If data is_bool then render json where key='result' and value=data

	 * @param mixed $data

	 */

	public function renderJSON($data)

	{

		if (is_bool($data))

		{

			$data = array('result' => $data);

		}

		header("Content-type: application/json;charset=utf-8");

		echo CJSON::encode($data);

		foreach (Yii::app()->log->routes as $route)

		{

			if ($route instanceof CWebLogRoute)

			{

				$route->enabled = false;

			}

		}

		Yii::app()->end();

	}



Then in my controller action instead of $this->render I call $this->renderJSON($withMyData);

Hope this helps

I found this solution.

In config i use a key for array.




'log'=>array(

	'class'=>'CLogRouter',

	'routes'=>array(

		'cweb' => array(

			'class'=>'CWebLogRoute',

			'levels'=>'trace',

			'categories'=>'system.db.CDbCommand,system.caching.CApcCache,vardump,debug',

			'showInFireBug'=>false,

		),

		.........



in my controller action




Yii::app()->log->routes['cweb']->enabled=false;