Here I have explained about "log" concept using file. It is available in yii. Just i used one new level log and saved this log information in individual file. Just add the following code in config/main.php
Add Log in main.php
I created one new level for my "mailError.log" file. When error occured the "mailError.log" file will create automatically and log information will save into that file.
<?php
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'CFileLogRoute',
'levels'=>'mailerror',
'categories'=>"system.*",
'logFile'=>'mailError.log',
),
array(
'class'=>'CFileLogRoute',
'levels'=>'error, warning',
),
),
),
?>
Save log into File
When model save failed or some failure case, I will add one message into "log" file using below code. We can use this anywhere in our application. Just we have to mention the levels of log. Here i added "mailerror" level.
<?php
if($mail->save())
{
echo "Success";
}else
{
Yii::log("Mailer Error ",'mailerror','system.*');
}
?>
-
anil