Yahoo! UI Library

console  3.0.0pr2

Yahoo! UI Library > console > Console
Search:
 
Filters

Class Console - extends Widget

Console creates a visualization for messages logged through calls to a YUI instance's Y.log( message, category, source ) method. The debug versions of YUI modules will include logging statements to offer some insight into the steps executed during that module's operation. Including log statements in your code will cause those messages to also appear in the Console. Use Console to aid in developing your page or application. Entry categories are also referred to as the log level, and entries are filtered against the configured logLevel.

Properties

_body - protected Node

Reference to the Node instance that will house the console messages.
Default Value: null

_head - protected Node

Reference to the Node instance containing the head contents.
Default Value: null

_timeout - protected Object

Object API returned from Y.later. Holds the timer id returned by setTimout for scheduling of buffered messages.
Default Value: null

buffer - Array

Array of normalized message objects awaiting printing.
Default Value: null

Console.ATTRS - static Object

Static property used to define the default attribute configuration of the Widget.

Console.BODY_TEMPLATE - static String

Markup template used to generate the DOM structure for the Console body (where the messages are inserted) when it is rendered. The template includes only the {placeholder} "console_bd_class", which is constributed by Console.CHROME_CLASSES.

Console.CHROME_CLASSES - static Object

Map (object) of classNames used to populate the placeholders in the Console.HEADER_TEMPLATE, Console.BODY_TEMPLATE, and Console.FOOTER_TEMPLATE markup when rendering the Console UI.

By default, the keys contained in the object are:

  • console_hd_class
  • console_bd_class
  • console_ft_class
  • console_controls_class
  • console_checkbox_class
  • console_pause_class
  • console_pause_label_class
  • console_button_class
  • console_clear_class
  • console_title_class

Console.ENTRY_CLASSES - static Object

Map (object) of classNames used to populate the placeholders in the Console.ENTRY_TEMPLATE markup when rendering a new Console entry.

By default, the keys contained in the object are:

  • entry_class
  • entry_meta_class
  • entry_cat_class
  • entry_src_class
  • entry_time_class
  • entry_content_class

Console.ENTRY_TEMPLATE - static String

Default markup template used to create the DOM structure for Console entries. The markup contains {placeholder}s for content and classes that are replaced via Y.substitute. The default template contains the {placeholder}s identified in Console.ENTRY_CLASSES as well as the following placeholders that will be populated by the log entry data:
  • cat_class
  • src_class
  • label
  • totalTime
  • elapsedTime
  • localTime
  • sourceAndDetail
  • message

Console.HEADER_TEMPLATE - static String

Markup template used to generate the DOM structure for the header section of the Console when it is rendered. The template includes these {placeholder}s:
  • console_hd_class - contributed by Console.CHROME_CLASSES
  • console_title_class - contributed by Console.CHROME_CLASSES
  • str_title - pulled from attribute strings.title

Console.LOG_LEVEL_ERROR - static Number

Static identifier for logLevel configuration setting to allow only incoming messages of logLevel "error" to generate Console entries.

Console.LOG_LEVEL_INFO - static Number

Static identifier for logLevel configuration setting to allow all incoming messages to generate Console entries.

Console.LOG_LEVEL_WARN - static Number

Static identifier for logLevel configuration setting to allow only incoming messages of logLevel "warn" or "error" to generate Console entries.

Console.NAME - static String

The identity of the widget.

Properties inherited from Attribute:

Properties inherited from Base:

Methods

_addToConsole

protected void _addToConsole ( node )
Inserts a Node into the console body at the top or bottom depending on the configuration value of newestOnTop.
Parameters:
node <Node> the node to insert into the console body
Returns: void

_afterConsoleLimitChange

protected void _afterConsoleLimitChange ( e )
Calls this._trimOldEntries() in response to changes in the configured consoleLimit attribute.
Parameters:
e <Event> Custom event for the attribute change
Returns: void

_afterPausedChange

protected void _afterPausedChange ( e )
Updates the UI and schedules or cancels the scheduled buffer printing operation.
Parameters:
e <Event> Custom event for the attribute change
Returns: void

_afterStringsChange

protected void _afterStringsChange ( e )
Updates the UI if changes are made to any of the strings in the strings attribute.
Parameters:
e <Event> Custom event for the attribute change
Returns: void

_clearTimeout

protected void _clearTimeout ( )
Clears the timeout for printing buffered messages.
Returns: void

_defEntryFn

protected void _defEntryFn ( e )
Buffers incoming message objects and schedules the printing.
Parameters:
e <Event> The Custom event carrying the message in its payload
Returns: void

_defResetFn

protected void _defResetFn ( )
Clears the console, resets the startTime attribute, enables and unpauses the widget.
Returns: void

_encodeHTML

protected _encodeHTML ( s )
Returns the input string with ampersands (&), <, and > encoded as HTML entities.
Parameters:
s <String> the raw string

_htmlEscapeMessage

protected _htmlEscapeMessage ( m )
Performs HTML escaping on strings in the message object.
Parameters:
m <Object> the normalized message object

_initConsole

protected void _initConsole ( )
Create the DOM structure for the console body—where messages are rendered.
Returns: void

_initFoot

protected void _initFoot ( )
Create the DOM structure for the footer elements.
Returns: void

_initHead

protected void _initHead ( )
Create the DOM structure for the header elements.
Returns: void

_isInLogLevel

protected void _isInLogLevel ( )
Determine if incoming log messages are within the configured logLevel to be buffered for printing.
Returns: void

_normalizeMessage

protected _normalizeMessage ( msg , cat , src )
Create a log entry message from the inputs including the following keys:
  • time - this moment
  • message - leg message
  • category - aka logLevel
  • source - when provided, the widget or util calling Y.log
  • sourceAndDetail - same as source but can include instance info
  • label - logLevel/category label for the entry
  • localTime - readable version of time
  • elapsedTime - ms since last entry
  • totalTime - ms since Console was instantiated or reset
Parameters:
msg <String> the log message
cat <String> OPTIONAL the category or logLevel of the message
src <String> OPTIONAL the source widget or util of the message

_onClearClick

protected void _onClearClick ( e )
Event handler for clicking on the Clear button. Pass-through to this.clearConsole().
Parameters:
e <Event> DOM event facade for the click event
Returns: void

_onLogEvent

protected void _onLogEvent ( msg , cat , src )
Responds to log events by normalizing qualifying messages and passing them along through the entry event for buffering etc.
Parameters:
msg <String> the log message
cat <String> OPTIONAL the category or logLevel of the message
src <String> OPTIONAL the source of the message (e.g. widget name)
Returns: void

_onPauseClick

protected void _onPauseClick ( e )
Event handler for clicking on the Pause checkbox to update the paused attribute.
Parameters:
e <Event> DOM event facade for the click event
Returns: void

_schedulePrint

protected void _schedulePrint ( )
Sets a timeout for buffered messages to be output to the console.
Returns: void

_setLogLevel

protected _setLogLevel ( v )
Setter method for logLevel attribute. Acceptable values are "error", "warn", "info", and Y.Console.LOG_LEVEL_ERROR, Y.Console.LOG_LEVEL_WARN, Y.Console.LOG_LEVEL_INFO. Any other value becomes Y.Console.LOG_LEVEL_INFO.
Parameters:
v <String|Number> String or numeric alias for the desired logLevel

_trimOldEntries

protected void _trimOldEntries ( )
Removes the oldest message entries from the UI to maintain the limit specified in the consoleLimit configuration.
Returns: void

_validateNewLogLevel

protected _validateNewLogLevel ( v )
Verifies input logLevel is one of Y.Console.LOG_LEVEL_ERROR, Y.Console.LOG_LEVEL_WARN, or Y.Console.LOG_LEVEL_INFO.
Parameters:
v <Number> requested logLevel

bindUI

protected void bindUI ( )
Set up event listeners to wire up the UI to the internal state.
Returns: void

clearConsole

void clearConsole ( )
Clear the console of messages and flush the buffer of pending messages.
Returns: void
Chainable: This method is chainable.

initializer

protected void initializer ( )
Constructor code. Set up the buffer and entry template, publish internal events, and subscribe to the configured logEvent.
Returns: void

log

void log ( * )
Wrapper for Y.log.
Parameters:
* <Any*> (all arguments passed through to Y.log)
Returns: void

printBuffer

void printBuffer ( )
Outputs all buffered messages to the console UI.
Returns: void
Chainable: This method is chainable.

printLogEntry

void printLogEntry ( m )
Prints the provided message to the console UI.
Parameters:
m <Object> Normalized message object
Returns: void
Chainable: This method is chainable.

renderUI

protected void renderUI ( )
Generate the Console UI.
Returns: void

reset

void reset ( )
Clears the console and resets internal timers.
Returns: void
Chainable: This method is chainable.

syncUI

void syncUI ( )
Sync the UI state to the current attribute state.
Returns: void

Events

consoleLimitChange

consoleLimitChange ( event )
Fires when the value for the configuration attribute 'consoleLimit' is changed. You can listen for the event using the on method if you wish to be notified before the attribute's value has changed, or using the after method if you wish to be notified after the attribute's value has changed.
Parameters:
event <Event.Facade> An Event Facade object with the following attribute specific properties added:
prevVal
The value of the attribute, prior to it being set
newVal
The value the attribute is to be set to
attrName
The name of the attribute being set
subAttrName
If setting a property within the attribute's value, the name of the sub-attribute property being set

defaultCategoryChange

defaultCategoryChange ( event )
Fires when the value for the configuration attribute 'defaultCategory' is changed. You can listen for the event using the on method if you wish to be notified before the attribute's value has changed, or using the after method if you wish to be notified after the attribute's value has changed.
Parameters:
event <Event.Facade> An Event Facade object with the following attribute specific properties added:
prevVal
The value of the attribute, prior to it being set
newVal
The value the attribute is to be set to
attrName
The name of the attribute being set
subAttrName
If setting a property within the attribute's value, the name of the sub-attribute property being set

defaultSourceChange

defaultSourceChange ( event )
Fires when the value for the configuration attribute 'defaultSource' is changed. You can listen for the event using the on method if you wish to be notified before the attribute's value has changed, or using the after method if you wish to be notified after the attribute's value has changed.
Parameters:
event <Event.Facade> An Event Facade object with the following attribute specific properties added:
prevVal
The value of the attribute, prior to it being set
newVal
The value the attribute is to be set to
attrName
The name of the attribute being set
subAttrName
If setting a property within the attribute's value, the name of the sub-attribute property being set

entry

entry ( event )
Triggers the processing of an incoming message via the default logic in _defEntryFn.
Parameters:
event <Event.Facade> An Event Facade object with the following attribute specific properties added:
message
The message data normalized into an object literal (see _normalizeMessage)
Preventable: This event is preventable by method e.preventDefault(). The default function executed by this event is _defEntryFn.

entryTemplateChange

entryTemplateChange ( event )
Fires when the value for the configuration attribute 'entryTemplate' is changed. You can listen for the event using the on method if you wish to be notified before the attribute's value has changed, or using the after method if you wish to be notified after the attribute's value has changed.
Parameters:
event <Event.Facade> An Event Facade object with the following attribute specific properties added:
prevVal
The value of the attribute, prior to it being set
newVal
The value the attribute is to be set to
attrName
The name of the attribute being set
subAttrName
If setting a property within the attribute's value, the name of the sub-attribute property being set

lastTimeChange

lastTimeChange ( event )
Fires when the value for the configuration attribute 'lastTime' is changed. You can listen for the event using the on method if you wish to be notified before the attribute's value has changed, or using the after method if you wish to be notified after the attribute's value has changed.
Parameters:
event <Event.Facade> An Event Facade object with the following attribute specific properties added:
prevVal
The value of the attribute, prior to it being set
newVal
The value the attribute is to be set to
attrName
The name of the attribute being set
subAttrName
If setting a property within the attribute's value, the name of the sub-attribute property being set

logEventChange

logEventChange ( event )
Fires when the value for the configuration attribute 'logEvent' is changed. You can listen for the event using the on method if you wish to be notified before the attribute's value has changed, or using the after method if you wish to be notified after the attribute's value has changed.
Parameters:
event <Event.Facade> An Event Facade object with the following attribute specific properties added:
prevVal
The value of the attribute, prior to it being set
newVal
The value the attribute is to be set to
attrName
The name of the attribute being set
subAttrName
If setting a property within the attribute's value, the name of the sub-attribute property being set

logLevelChange

logLevelChange ( event )
Fires when the value for the configuration attribute 'logLevel' is changed. You can listen for the event using the on method if you wish to be notified before the attribute's value has changed, or using the after method if you wish to be notified after the attribute's value has changed.
Parameters:
event <Event.Facade> An Event Facade object with the following attribute specific properties added:
prevVal
The value of the attribute, prior to it being set
newVal
The value the attribute is to be set to
attrName
The name of the attribute being set
subAttrName
If setting a property within the attribute's value, the name of the sub-attribute property being set

newestOnTopChange

newestOnTopChange ( event )
Fires when the value for the configuration attribute 'newestOnTop' is changed. You can listen for the event using the on method if you wish to be notified before the attribute's value has changed, or using the after method if you wish to be notified after the attribute's value has changed.
Parameters:
event <Event.Facade> An Event Facade object with the following attribute specific properties added:
prevVal
The value of the attribute, prior to it being set
newVal
The value the attribute is to be set to
attrName
The name of the attribute being set
subAttrName
If setting a property within the attribute's value, the name of the sub-attribute property being set

pausedChange

pausedChange ( event )
Fires when the value for the configuration attribute 'paused' is changed. You can listen for the event using the on method if you wish to be notified before the attribute's value has changed, or using the after method if you wish to be notified after the attribute's value has changed.
Parameters:
event <Event.Facade> An Event Facade object with the following attribute specific properties added:
prevVal
The value of the attribute, prior to it being set
newVal
The value the attribute is to be set to
attrName
The name of the attribute being set
subAttrName
If setting a property within the attribute's value, the name of the sub-attribute property being set

printTimeoutChange

printTimeoutChange ( event )
Fires when the value for the configuration attribute 'printTimeout' is changed. You can listen for the event using the on method if you wish to be notified before the attribute's value has changed, or using the after method if you wish to be notified after the attribute's value has changed.
Parameters:
event <Event.Facade> An Event Facade object with the following attribute specific properties added:
prevVal
The value of the attribute, prior to it being set
newVal
The value the attribute is to be set to
attrName
The name of the attribute being set
subAttrName
If setting a property within the attribute's value, the name of the sub-attribute property being set

reset

reset ( event )
Triggers the reset behavior via the default logic in _defResetFn.
Parameters:
event <Event.Facade> Event Facade object
Preventable: This event is preventable by method e.preventDefault(). The default function executed by this event is _defResetFn.

scrollIntoViewChange

scrollIntoViewChange ( event )
Fires when the value for the configuration attribute 'scrollIntoView' is changed. You can listen for the event using the on method if you wish to be notified before the attribute's value has changed, or using the after method if you wish to be notified after the attribute's value has changed.
Parameters:
event <Event.Facade> An Event Facade object with the following attribute specific properties added:
prevVal
The value of the attribute, prior to it being set
newVal
The value the attribute is to be set to
attrName
The name of the attribute being set
subAttrName
If setting a property within the attribute's value, the name of the sub-attribute property being set

startTimeChange

startTimeChange ( event )
Fires when the value for the configuration attribute 'startTime' is changed. You can listen for the event using the on method if you wish to be notified before the attribute's value has changed, or using the after method if you wish to be notified after the attribute's value has changed.
Parameters:
event <Event.Facade> An Event Facade object with the following attribute specific properties added:
prevVal
The value of the attribute, prior to it being set
newVal
The value the attribute is to be set to
attrName
The name of the attribute being set
subAttrName
If setting a property within the attribute's value, the name of the sub-attribute property being set

stringsChange

stringsChange ( event )
Fires when the value for the configuration attribute 'strings' is changed. You can listen for the event using the on method if you wish to be notified before the attribute's value has changed, or using the after method if you wish to be notified after the attribute's value has changed.
Parameters:
event <Event.Facade> An Event Facade object with the following attribute specific properties added:
prevVal
The value of the attribute, prior to it being set
newVal
The value the attribute is to be set to
attrName
The name of the attribute being set
subAttrName
If setting a property within the attribute's value, the name of the sub-attribute property being set

Configuration Attributes

consoleLimit - Number

Maximum number of Console entries allowed in the Console body at one time. This is used to keep acquired messages from exploding the DOM tree and impacting page performance.
Default Value: 500

defaultCategory - String

If a category is not specified in the Y.log(..) statement, this category will be used. Category is also called "log level".
Default Value: "info"

defaultSource - String

If a source is not specified in the Y.log(..) statement, this source will be used.
Default Value: "global"

entryTemplate - String

Markup template used to create the DOM structure for Console entries.
Default Value: (see Console.ENTRY_TEMPLATE)

lastTime - Date

The precise time the last entry was logged. Used to measure elapsed time between log messages.
Default Value: The moment the console module is used

logEvent - String

Name of the custom event that will communicate log messages.
Default Value: "yui:log"

logLevel - String|Number

Minimum entry log level to render into the Console. The initial logLevel value for all Console instances defaults from the Y.config.logLevel YUI configuration, or Console.LOG_LEVEL_INFO if that configuration is not set. Possible values are "info", "warn", "error" (case insensitive), or the corresponding statics Console.LOG_LEVEL_INFO and so on.
Default Value: Y.config.logLevel or Console.LOG_LEVEL_INFO

newestOnTop - Boolean

New entries should display at the top of the Console or the bottom?
Default Value: true

paused - boolean

Boolean to pause the outputting of new messages to the console. When paused, messages will accumulate in the buffer.
Default Value: false

printTimeout - Number

Millisecond timeout to maintain before emptying buffer of Console entries to the UI.
Default Value: 100

scrollIntoView - Boolean

When new entries are added to the Console UI, should they be scrolled into view?
Default Value: true

startTime - Date

The baseline time for this Console instance, used to measure elapsed time from the moment the console module is used to the moment each new entry is logged (not rendered). This value is reset by the instance method myConsole.reset().
Default Value: The moment the console module is used

strings - Object

Collection of strings used to label elements in the Console UI. Default collection contains the following name:value pairs:
  • title : "Log Console"
  • pause : "Pause"
  • clear : "Clear"

Configuration attributes inherited from Widget:

Configuration attributes inherited from Base:


Copyright © 2008 Yahoo! Inc. All rights reserved.