Question

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.

Était-ce utile?

La 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

Autres conseils

Not 100% sure of what I'm saying, but it seems that you can't create your own level of log:

Message level should be one of the following values:

  • trace: this is the level used by Yii::trace. It is for tracing the execution flow of the application during development.
  • info: this is for logging general information.
  • profile: this is for performance profile which is to be described shortly.
  • warning: this is for warning messages.
  • error: this is for fatal error messages.

Source

You should change the category of your log instead of the level:

echo Yii::log("Mailer Error ",'error','mailerror');

And in the config:

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

try change to: echo Yii::log("Mailer Error ",'error','system.mailerror'); (and better using CLogger::LEVEL_ERROR instead error)

UPDATE
For this testing you need to some reconfigurate CLogger. Try insert it before Yii::log

    $logger = Yii::getLogger();
    $logger->autoFlush = 1;
    $logger->autoDump = true;
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top