Obviously I didn’t… however why do I need to preload it? in this guide there is only laconic “in order to use… you have to preload” and no explanation. What is so special with this particular component that it has to be preloaded?
Well… i does not do any trick because my problem is different. Log routes are declared properly. my problem is: why do I have to preload (instantiate on every request) "log" component to make it work at all.
I was pointed to manual that says “you have to preload”, but I could not find the rason for that. Instead I have found something like credo of Yii: “Yii only loads the features that you need. It has powerful caching support. It is explicitly designed to work efficiently with AJAX.” which in this context is not so true…
I try to look at CLogger code but I could not even find "init" method… so what is so special about logger that is HAS TO BE preloaded?
In my application case any logs are produced in 20-30% requests, others are simple listing or viewing requests without any logs. In heavily loeaded application preloading "log" component on those 70% of requests can be a simple waste. This is why I am curious to know why it is necesary…
I’m not sure about this, but you may try a call to Yii::app()->getComponent() in the requests where logging is needed. The preload process will call this method for each specified component.
What you configure as ‘log’ component is in fact CLogRouter, not CLogger. logger YiiBase member is created when needed (on first call to ‘log’ function). So far, so good.
Now - why is CLogger not instantiating LogRouter on first log? Current design introduces ‘onFlush’ event for CLogger and CLogRouter attaches itself and listens for that event. This way logs flow from CLogger to Router. This explains why you have to preload ‘logger’ - CLogRouter needs to be instantiated to attach itself to event and receive logs. If you don’t create CLogRouter logs won’t be processed and stored (or whatever logroutes do with logs).
After this investigation and answering to my primary question “why do we have to preload logger?” I have another question - is this event pattern necesary? why CLogger cannot just push logs to CLogRouter object (instantiated on demand) and that router split logs to specific routes? I think this way everything would be simplier…
@tri - your solution would work, as it ensures component is instantiated just before my first log. However it is not so pretty, as I have to call that additional function before every log i my code… For now I will preload logger component…