During the development stage, I wanted a way to make my own log messages easier to identify in the (potentially) long list at the bottom of the page when using CWebLogRoute.
I know we can apply different message levels to different log routes, but I still wanted to see all the other messages.
So, I decided to add two CWebLogRoute entries to my main configuration:
This causes two “application log” boxes to appear at the end of the web page, in the sequence listed above, using the defined levels (the second array has no ‘levels’, so displays all log entries).
Then, wherever I use Yii::log(…), I specify ‘mine’ as the level. This causes my log message(s) to appear in both “application log” boxes. The first log box shows only my messages with a level of “mine”, and the second log box shows all messages, with mine (or “mine”, if you will) appearing in the relevant position in the sequence of events.
Sorry if this is obvious to the masses, but I thought I could make my own small contribution in case there are other noobs like me out there
I agree that may be one way of doing it, but I wanted my own messages to "float" to the top of the logs so that I did not need to scroll through all of the messages.
Also, the way I achieved it did not require any modifications to code other than a couple of lines in the configuration.
I suppose it is down to personal preference…thanks for the suggestion and for being my first responder!
Hehe, a little hackish (i’ve never thought about bringing up my own levels), because the guide states that they should be one of trace, info, profile, warning or error. But if it works, why not. Interesting approach, though. .
EDIT:
On second thought: Maybe using a custom category for your logs would be the better idea? You can even filter different sub categories (separated with ".").
In fact, I was surprised that Yii allowed me to do it. I checked through the source code and couldn’t find anywhere that restricted the level types, so I wondered what would happen if I tried.
If levels are ever defined / restricted in future Yii releases, then the approach would fall over, but until then, it solved my problem
Maybe we should make a “feature request” that the levels are never restricted, just so that we have the flexibility to take whatever path works for us. After all, no extra work would be generated for the Yii developers to “add” this as a feature
Categories are a much more elegant solution, and an "approved" approach.
Just for curiosity’s sake, I use a category of ‘mine.{class name}.{function name}’, and a level of ‘info’, which causes my messages to appear a different colour in the complete log, and also allows me to group my messages (as per my initial post above). The bonus is that I can clearly see what is generating the messages, without having to give extra information in the message itself.