Yii::trace not working all the time?

Hi everyone,

as far as I dig with Yii as so more questions that the documentation can not explain I get.

I have a model class Server extending CActiveRecord. The method afterSave() is overwritten with


protected function afterSave() {

		Yii::trace("Please help me!","server.HelperError!!!!!!!!!!");

		parent::afterSave();

	}

But I do not see that message in my trace. Everything else is in the trace log, except this message.

The configuration in main.php is:


'log'=>array(

			'class'=>'CLogRouter',

			'routes'=>array(

				array(

					'class'=>'CWebLogRoute',

					'levels'=>'trace,info,error, warning',					

				),

First I thought that the method is not called, but when I changed the code to


protected function afterSave() {

		throw new CDbException("Error");

		parent::afterSave();

	}

The exception is raised. The same goes with Yii::log().

What is wrong here?

Thanks in advance and best regards,

Danny

Since you do not explicitly specify category in the log config, you should expect all categories to be logged, including your own "funny" category. But I recommend you first try with category omitted, then try a simpler version of your custom category. See the API reference for more details.

/Tommy

Hi Tommy,

thanks for your replay. Even with


protected function afterSave() {

                Yii::trace("Please help me!");

                parent::afterSave();

        }

The issue is the same. Really strange. Even with xdebug I can see that I am entering this method. I try to recreate this issue with a new project, maybe there is something wrong with the project itself. But I did not made really magic here.

Kind regards,

Danny

Hi,

I tried it in the tutorial example of the blog app. I added the trace in the afterSave method of the class Post:


protected function afterSave() {

		

		parent::afterSave();

		Yii::trace("Everything fine after afterSave()");

		Tag::model()->updateFrequency($this->_oldTags, $this->tags);

	}

Changing the original config to:


'log'=>array(

			'class'=>'CLogRouter',

			'routes'=>array(

				array(

					'class'=>'CWebLogRoute',

					'levels'=>'trace, error, warning',

				),

				// uncomment the following to show log messages on web pages

				/*

				array(

					'class'=>'CWebLogRoute',

				),

				*/

			),

		),

Resulting in no trace entry of that call in the log. See attached file.

Could you check whether the afterSave is actually called? Can you use trace in your upate or create actions to see if trace is called there?

And include your parent::afterSave(); at the end of the function process: return parent::afterSave();

Maybe your controller action calls redirect() immediately after a successful save and CWebLogRoute shows the log for the new request (the page you redirected to)?

Hi,

@Antonio:

the method is called. It throws an exception if I change the code to:


protected function afterSave() {

                throw new CDbException("Error");

                parent::afterSave();

        }

@phtamas:

I use the demo blog app to ensure, that nothing fancy is creating this strange result.

Actually I found that the traces in CWebLogRoute is shorter than the trace with CFileLogRoute. I thought that bot components are swapable to providing the same result. It is not true, I found my message with the CFileLogRoute activated.

Is this a bug or a feature? What makes CWebLogRoute to show one trace msg and not another one?

Best regards,

Danny

Hi,

it is really strange, after switching the Logger to CFileLogRouter I saw the traces of the calls of Yii::trace in the method afterSave(). But after a restart of the Apache the issues occurs again. If I call Yii::trace in the method afterSave() not trace is written into the log. When I raise an exception in place of the Yii::trace the exception is raised, so the method is called.

Anyone a clue?

Kind regards,

Danny

Just wanted to say I am having this same issue. Anyone know what is up? I did make sure my application.log is owned by Apache’s process (_www). I also tried chmod to 0666 but that didn’t help.

You only see trace messages in debug mode. Did you define YII_DEBUG as true in your index.php?

are you using yiilite?

don’t use yiilite when you are in development mode