Hi! im logging all erors and warnings, and sending to email. Problem is if someone, for example, accessing not existing page (404) , i get email. And yesterday google spider was trying to access robots.txt and i didn’t have that. So i got 35 emails ;/ and one problem to resolve with message logging. As you understand problem is not in robots.txt file but in general. someone wants to get some page , it doesnt exist and it goes to email. not cool
and question is How can i ignore some cateories rom log router defined categories?
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'CFileLogRoute',
'levels'=>'error, warning', //logging all errors and warnings
),
array(
'class'=>'CEmailLogRoute',
'levels'=>'error', // send to emails only errors
'email'=>'admin@example.com',
'categories'=>'!exception.CHttpException.404' // and here i want to put ignore statement to not send 404 errors
),
),
),
can i do that somehow?
or there i should do some workaround.
maybe i can remove " exception.CHttpException.* " from error category. this would resolve my problem as well.
You could try to configure a custom log filter (which should extend CLogFilter). See source of CLogFilter::filter(&$logs). It should work, if you remove the unwanted entries from $logs there. Each $logs item is an array with these values:
Was just a metodological question. As none read the log file, is better to send email for relevant notice.
I guess that this is why exist CEmailLogRouter, because people are reading emails much more often of how much are reading the log file.
So the questio is: what are log that worth to be sent via email? Of corse software failure are worth, because programmer can patch the problem before a customer call (I think that this is called ‘proactivity’ from 2.0 philosophs).
Should ‘page not found’ be sent via mail? In my opinion yes.
A page not find can be or a bug in the application (broken link) and so should be logged, or an address that a user manually entered, maybe with malicious ideas, and in this case should be also logged.
There are bot (or paranoid browser) that look for special files. In my opinion is better to place this few file and continue reciving all signalation.
Too many emails cause that you ignore them after some time. I’d rather not get an email for each 404 as this is a too common error on any site. BTW you would make it very easy for an attacker to bomb your inbox .
Hmm. I’d say you could create a ticket for this. The way filters are implemented now, they are meant to format/decorate the log entries before sending. I think it makes sense to also enable filtering out a message with a filter. The fix would be a small change in CLogRoute::collectLogs().
Instead of:
public function collectLogs($logger, $processLogs=false)
{
$logs=$logger->getLogs($this->levels,$this->categories);
$this->logs=empty($this->logs) ? $logs : array_merge($this->logs,$logs);
if($processLogs && !empty($this->logs))
{
if($this->filter!==null)
Yii::createComponent($this->filter)->filter($this->logs);
$this->processLogs($this->logs);
}
}
it needs to be:
public function collectLogs($logger, $processLogs=false)
{
$logs=$logger->getLogs($this->levels,$this->categories);
$this->logs=empty($this->logs) ? $logs : array_merge($this->logs,$logs);
if($processLogs && !empty($this->logs))
{
if($this->filter!==null)
Yii::createComponent($this->filter)->filter($this->logs);
if (!empty($this->logs))
$this->processLogs($this->logs);
}
}
As a workaround you could extend CEmailLogRoute and override that method there.
Here’s a complete example of filtering out / ignoring 404 errors based on narkomanC’s filter. This will not require changes to the core files and will not send blank email alerts.