Yii Framework Forum: CLogFilter logVars - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

CLogFilter logVars Rate Topic: -----

#1 User is offline   jmcmasterj 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 18-June 09

Posted 17 October 2009 - 01:42 PM

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'?
0

#2 User is offline   lubosdz 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 114
  • Joined: 25-July 10
  • Location:Slovakia, Bratislava

Posted 03 July 2011 - 05:44 AM

View Postjmcmasterj, on 17 October 2009 - 01:42 PM, said:

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
Yii extension: Captcha Extended

Greatest discoveries in 22nd century will be about the gravitation. | http://www.synet.sk | http://ipdf.sk
0

#3 User is offline   Amy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 22
  • Joined: 04-February 13

Posted 14 October 2013 - 03:18 PM

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
2

#4 User is offline   realtebo 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 03-October 12
  • Location:Ferrara

Posted 30 January 2014 - 08:42 AM

what is "security" level? I've not seen it before.
PS: thanks for the example!
Il computer non ragiona, ma ha sempre ragione.
Ricordalo quando fai il debug
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users