CLogFilter logVars

I am using CLogFilter to show $_SERVER variables using logVars. Is it possible to filter the $_SERVER variables to show only select ones such as ‘REMOTE_ADDR’?

Nope, default implementation will export whole array. You must override CLogFilter::getContext() in your own class e.g.




class LogFilter extends CCLogFilter{


   protected function getContext(){

       ... you decide what is logged ...

   }


}



and also configure main.php to use your filter class like:




...

'log'=>array(

	'class'=>'CLogRouter',

	'routes'=>array(

		array(

			'class'=>'DbLogRoute',

			'levels'=>'error, warning',

			'categories'=>'exception.*',

			'autoCreateLogTable'=>true,

			'connectionID'=>'db',

			'logTableName'=>'im_log',

			'filter'=>'LogFilter',

		),

	),

),

...



Lubos

As of June 2013 it’s possible to log individual elements of $_SERVER (or any superglobal). The following example logs 2 elements from _SERVER and all of _GET:




'log'=>array(

	'class'=>'CLogRouter',

	'routes'=>array(

		array(

			'class'=>'CFileLogRoute',

			'levels'=>'error, warning, log, trace, security',

			'filter'=>array(

				'class'=>'CLogFilter',

				'logUser'=>true,

				'logVars' =>array(array('_SERVER','REMOTE_ADDR'),

					array('_SERVER', 'REDIRECT_URL'),

					'_GET',

				),

			),

		),

	),

),



Check to see which version of the framework you have. Get updated source on GitHub

what is “security” level? I’ve not seen it before.

PS: thanks for the example!