loggingyiiyii-events

CFileLogRoute error


i want to create new log file for with my custom error or custom messages but i am not able to do that. even i have made the changes in main.php file as well.

        array(
                'class'=>'CFileLogRoute',
                'levels'=>'mailerror',
                'categories'=>"system.*",
                'logFile'=>'mailError.log'.date('d-m-y s'),
            ),

            array(
                'class'=>'CFileLogRoute',
                'levels'=>'error, info',
            ),

and after this when i am trying to test my code on index.php this is my code

echo Yii::log("Mailer Error ",'mailerror','system.*');

then this is not working. nothing is happening.


Solution

  • ok I Got the error. as i told that i am trying to run these code on my index.php file which is application index file then this was not working. but when i tried the code in my view file or any or view file located in protected view folder then its working fine. also i changed my code into this

    'routes'=>array(
                array(
                    'class'=>'CFileLogRoute',
                    'levels'=>'mailerror',
                    'categories'=>"system.*",
                    'logFile'=>'mailError.log'.date('d-m-y s'),
                ),
    
                array(
                    'class'=>'CFileLogRoute',
                    'levels'=>'error, info',
                ),
    

    this code basically generate log file at every second if i remove 's' from date then this will generate file on daily basis.

    echo Yii::log("Error : While occuring with function in file",'mailerror','system.*');
    echo Yii::log("Error : error in another option",'mailerror','system.*');
    echo Yii::log("Error : error diff function",'mailerror','system.*');
    

    so this my function calling from admin.php file located in view folder. so the main error was 'i was trying to call log function' from application index file for testing and when i tried from any other view file then its working fine. any how thanks friends for your help and support. thanks CreatoR & darkheir