0

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.

Manquer
  • 7,390
  • 8
  • 42
  • 69
Anil Kumar
  • 701
  • 11
  • 28

3 Answers3

1

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

Anil Kumar
  • 701
  • 11
  • 28
0

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'),
),
darkheir
  • 8,844
  • 6
  • 45
  • 66
  • In your conf do you have 'preload'=>array('log')? Do you have the folder "runtime" in your project? is the other logs working? – darkheir Oct 23 '13 at 11:54
  • yes i do have folder runtime also i do have other log working too. – Anil Kumar Oct 23 '13 at 11:58
  • and if you change the logfile to put it whitout the date? (just trying) – darkheir Oct 23 '13 at 12:02
  • if i put it without date even then this will not work.. the main issue was i was trying to test this in my index.php file which i mentioned in my question. i tried in any other file that works file for me. thanks – Anil Kumar Oct 23 '13 at 12:07
  • but can i access this yii:log function from my components file or any of helper file which i have created in components folder. ? and will it create log from components. – Anil Kumar Oct 23 '13 at 12:39
0

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;
CreatoR
  • 1,654
  • 10
  • 14