Console: Creating a Console for debugging
This example walks through the basics of setting up and logging messages to a YUI Console instance. Three Console instances are created with slightly different configurations. All calls to Y.log(..) will be broadcast to every Console.
Basic Console
New messages added to bottom
Custom strings
Rendered in default location (top right)
Log some messages
Markup not required
The primary purpose of the Console is to aid in debugging your application. As such, it doesn't make much sense to require your page to include markup for something that is not bound for production.
However, Console is built on the Widget framework, so for this example, we'll illustrate three ways to place a Console instance on the page:
- Providing a
boundingBoxnode reference. - Providing both
boundingBoxandcontentBoxreferences. - Using the default rendering behavior.
For the first two cases, we need to set up some markup. We'll throw in some placeholder content for the third.
Then instantiate the Console instances.
Log some messages
In your code, inserting calls to Y.log(..) will cause the content of those log messages to be broadcast to every Console instance present in the YUI instance. We'll illustrate this by creating some buttons to log various types of messages.
A touch of CSS
For this example, it was more appropriate for the Consoles to be nested in the content for coherency. To facilitate this, the default absolute positioning for the first two Consoles was overridden to static. Also, some page styles cascaded to the Consoles, so a handful of other styles needed to be forcibly reapplied using more specific selectors. The CSS is included below.
