console.js revision b32d148b0052e1f874e9bc9803bef729bf859d97
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * A user interface for viewing log messages.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @module console
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith C_ENTRY_CONTENT = getCN(CONSOLE,ENTRY,'content'),
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Console creates a visualization for messages logged through calls to a YUI
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * instance's <code>Y.log( message, category, source )</code> method. The
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * debug versions of YUI modules will include logging statements to offer some
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * insight into the steps executed during that module's operation. Including
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * log statements in your code will cause those messages to also appear in the
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Console. Use Console to aid in developing your page or application.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Entry categories are also referred to as the log level, and entries are
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * filtered against the configured logLevel.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @class Console
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @extends Widget
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith Console.superclass.constructor.apply(this,arguments);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * The identity of the widget.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @property Console.NAME
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type String
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Static identifier for logLevel configuration setting to allow all
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * incoming messages to generate Console entries.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @property Console.LOG_LEVEL_INFO
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type Number
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Static identifier for logLevel configuration setting to allow only
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * incoming messages of logLevel "warn" or "error"
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * to generate Console entries.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @property Console.LOG_LEVEL_WARN
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type Number
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Static identifier for logLevel configuration setting to allow only
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * incoming messages of logLevel "error" to generate
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Console entries.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @property Console.LOG_LEVEL_ERROR
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type Number
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Map (object) of classNames used to populate the placeholders in the
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Console.ENTRY_TEMPLATE markup when rendering a new Console entry.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <p>By default, the keys contained in the object are:</p>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>entry_class</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>entry_meta_class</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>entry_cat_class</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>entry_src_class</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>entry_time_class</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>entry_content_class</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @property Console.ENTRY_CLASSES
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type Object
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Map (object) of classNames used to populate the placeholders in the
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Console.HEADER_TEMPLATE, Console.BODY_TEMPLATE, and
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Console.FOOTER_TEMPLATE markup when rendering the Console UI.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <p>By default, the keys contained in the object are:</p>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>console_hd_class</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>console_bd_class</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>console_ft_class</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>console_controls_class</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>console_checkbox_class</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>console_pause_class</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>console_pause_label_class</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>console_button_class</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>console_clear_class</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>console_title_class</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @property Console.CHROME_CLASSES
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type Object
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Markup template used to generate the DOM structure for the header
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * section of the Console when it is rendered. The template includes
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * these {placeholder}s:
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>console_hd_class - contributed by Console.CHROME_CLASSES</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>console_title_class - contributed by Console.CHROME_CLASSES</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>str_title - pulled from attribute strings.title</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @property Console.HEADER_TEMPLATE
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type String
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith '<div class="{console_hd_class}">'+
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith '<h4 class="{console_title_class}">{str_title}</h4>'+
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Markup template used to generate the DOM structure for the Console body
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * (where the messages are inserted) when it is rendered. The template
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * includes only the {placeholder} "console_bd_class", which is
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * constributed by Console.CHROME_CLASSES.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @property Console.BODY_TEMPLATE
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type String
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith BODY_TEMPLATE : '<div class="{console_bd_class}"></div>',
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Markup template used to generate the DOM structure for the footer
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * section of the Console when it is rendered. The template includes
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * many of the {placeholder}s from Console.CHROME_CLASSES as well as:
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>id_guid - generated unique id, relates the label and checkbox</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>str_pause - pulled from attribute strings.pause</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>str_clear - pulled from attribute strings.clear</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @property Console.HEADER_TEMPLATE
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type String
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith '<div class="{console_ft_class}">'+
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith '<div class="{console_controls_class}">'+
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith '<input type="checkbox" class="{console_checkbox_class} '+
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith '{console_pause_class}" value="1" id="{id_guid}"> '+
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith '<label for="{id_guid}" class="{console_pause_label_class}">'+
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith '{str_pause}</label>' +
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith '<input type="button" class="'+
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith '{console_button_class} {console_clear_class}" '+
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith 'value="{str_clear}">'+
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Default markup template used to create the DOM structure for Console
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * entries. The markup contains {placeholder}s for content and classes
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * that are replaced via Y.substitute. The default template contains
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * the {placeholder}s identified in Console.ENTRY_CLASSES as well as the
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * following placeholders that will be populated by the log entry data:
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>cat_class</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>src_class</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>label</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>totalTime</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>elapsedTime</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>localTime</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>sourceAndDetail</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>message</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @property Console.ENTRY_TEMPLATE
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type String
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith '<pre class="{entry_class} {cat_class} {src_class}">'+
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith '<div class="{entry_meta_class}">'+
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith '<span class="{entry_cat_class}">'+
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith '{label}</span>'+
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith '<span class="{entry_time_class}">'+
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith ' {totalTime}ms (+{elapsedTime}) {localTime}:'+
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith '<p class="{entry_src_class}">'+
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith '{sourceAndDetail}'+
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith '<p class="{entry_content_class}">{message}</p>'+
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Static property used to define the default attribute configuration of
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * the Widget.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @property Console.ATTRS
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @Type Object
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Name of the custom event that will communicate log messages.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @attribute logEvent
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type String
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @default "yui:log"
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Collection of strings used to label elements in the Console UI.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Default collection contains the following name:value pairs:
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>title : "Log Console"</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>pause : "Pause"</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>clear : "Clear"</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @attribute strings
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type Object
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Boolean to pause the outputting of new messages to the console.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * When paused, messages will accumulate in the buffer.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @attribute paused
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type boolean
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @default false
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * If a category is not specified in the Y.log(..) statement, this
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * category will be used. Category is also called "log level".
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @attribute defaultCategory
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type String
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @default "info"
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * If a source is not specified in the Y.log(..) statement, this
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * source will be used.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @attribute defaultSource
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type String
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @default "global"
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Markup template used to create the DOM structure for Console entries.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @attribute entryTemplate
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type String
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @default (see Console.ENTRY_TEMPLATE)
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Minimum entry log level to render into the Console. The initial
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * logLevel value for all Console instances defaults from the
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Y.config.logLevel YUI configuration, or Console.LOG_LEVEL_INFO if
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * that configuration is not set.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Possible values are "info", "warn",
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * "error" (case insensitive), or the corresponding statics
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Console.LOG_LEVEL_INFO and so on.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @attribute logLevel
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type String|Number
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @default Y.config.logLevel or Console.LOG_LEVEL_INFO
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith validator : function (v) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith set : function (v) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith return this._setLogLevel(v);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Millisecond timeout to maintain before emptying buffer of Console
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * entries to the UI.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @attribute printTimeout
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type Number
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @default 100
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Maximum number of Console entries allowed in the Console body at one
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * time. This is used to keep acquired messages from exploding the
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * DOM tree and impacting page performance.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @attribute consoleLimit
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type Number
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @default 500
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * New entries should display at the top of the Console or the bottom?
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @attribute newestOnTop
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type Boolean
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @default true
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * When new entries are added to the Console UI, should they be
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * scrolled into view?
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @attribute scrollIntoView
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type Boolean
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @default true
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * The baseline time for this Console instance, used to measure elapsed
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * time from the moment the console module is <code>use</code>d to the
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * moment each new entry is logged (not rendered).
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * This value is reset by the instance method myConsole.reset().
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @attribute startTime
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type Date
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @default The moment the console module is <code>use</code>d
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith value : new Date()
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * The precise time the last entry was logged. Used to measure elapsed
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * time between log messages.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @attribute lastTime
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type Date
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @default The moment the console module is <code>use</code>d
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith value : new Date(),
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Reference to the Node instance containing the head contents.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @property _head
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type Node
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @default null
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Reference to the Node instance that will house the console messages.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @property _body
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type Node
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @default null
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Reference to the Node instance containing the footer contents.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @property _head
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type Node
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @default null
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Object API returned from <code>Y.later</code>. Holds the timer id
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * returned by <code>setTimout</code> for scheduling of buffered messages.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @property _timeout
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type Object
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @default null
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Array of normalized message objects awaiting printing.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @property buffer
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type Array
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @default null
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Wrapper for <code>Y.log</code>.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method log
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param {Any*} * (all arguments passed through to <code>Y.log</code>)
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith log : function () {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Clear the console of messages and flush the buffer of pending messages.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method clearConsole
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @chainable
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith clearConsole : function () {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith // TODO: clear event listeners from console contents
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith return this;
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Clears the console and resets internal timers.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method reset
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @chainable
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith reset : function () {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith return this;
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Outputs all buffered messages to the console UI.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method printBuffer
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @chainable
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith printBuffer: function () {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith // TODO: use doc frag
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith for (i = 0, len = messages.length; i < len; ++i) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith return this;
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Prints the provided message to the console UI.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method printLogEntry
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param m {Object} Normalized message object
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @chainable
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith printLogEntry : function (m) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith var n = create(substitute(this.get('entryTemplate'),m));
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith return this;
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Constructor code. Set up the buffer and entry template, publish
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * internal events, and subscribe to the configured logEvent.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method initializer
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith initializer : function () {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith Y.on(this.get('logEvent'),Y.bind(this._onLogEvent,this));
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Triggers the processing of an incoming message via the default logic
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * in _defEntryFn.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @event entry
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param event {Event.Facade} An Event Facade object with the following attribute specific properties added:
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <dt>message</dt>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <dd>The message data normalized into an object literal (see _normalizeMessage)</dd>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @preventable _defEntryFn
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith this.publish(ENTRY, { defaultFn: this._defEntryFn });
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Triggers the reset behavior via the default logic in _defResetFn.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @event reset
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param event {Event.Facade} Event Facade object
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @preventable _defResetFn
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith this.publish(RESET, { defaultFn: this._defResetFn });
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Generate the Console UI.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method renderUI
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith renderUI : function () {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Sync the UI state to the current attribute state.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method syncUI
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith syncUI : function () {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Set up event listeners to wire up the UI to the internal state.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method bindUI
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith bindUI : function () {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith this.get(CONTENT_BOX).query('input[type=checkbox].'+C_PAUSE).
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith this.get(CONTENT_BOX).query('input[type=button].'+C_CLEAR).
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith // Attribute changes
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith this.after('stringsChange', this._afterStringsChange);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith this.after('pausedChange', this._afterPausedChange);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith this.after('consoleLimitChange', this._afterConsoleLimitChange);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Create the DOM structure for the header elements.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method _initHead
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith _initHead : function () {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith this._head = create(substitute(Console.HEADER_TEMPLATE,info));
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith cb.insertBefore(this._head,cb.get('firstChild'));
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Create the DOM structure for the console body—where messages are
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method _initConsole
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith _initConsole : function () {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Create the DOM structure for the footer elements.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method _initFoot
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith _initFoot : function () {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith this._foot = create(substitute(Console.FOOTER_TEMPLATE,info));
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Determine if incoming log messages are within the configured logLevel
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * to be buffered for printing.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method _isInLogLevel
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Create a log entry message from the inputs including the following keys:
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>time - this moment</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>message - leg message</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>category - aka logLevel</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>source - when provided, the widget or util calling Y.log</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>sourceAndDetail - same as source but can include instance info</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>label - logLevel/category label for the entry</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>localTime - readable version of time</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>elapsedTime - ms since last entry</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>totalTime - ms since Console was instantiated or reset</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @mehod _normalizeMessage
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param msg {String} the log message
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param cat {String} OPTIONAL the category or logLevel of the message
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param src {String} OPTIONAL the source widget or util of the message
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @return Object the message object
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith time : new Date(),
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith sourceAndDetail : src || this.get('defaultSource'),
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith // Extract m.source "Foo" from m.sourceAndDetail "Foo bar baz"
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith m.source = RE_INLINE_SOURCE.test(m.sourceAndDetail) ?
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Sets a timeout for buffered messages to be output to the console.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method _schedulePrint
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith _schedulePrint : function () {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Inserts a Node into the console body at the top or bottom depending on
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * the configuration value of newestOnTop.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method _addToConsole
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param node {Node} the node to insert into the console body
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith bd.insertBefore(node,toTop ? bd.get('firstChild') : null);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Performs HTML escaping on strings in the message object.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method _htmlEscapeMessage
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param m {Object} the normalized message object
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @return Object a clone of the message object with proper escapement
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith _htmlEscapeMessage : function (m) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith m.sourceAndDetail = this._encodeHTML(m.sourceAndDetail);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Removes the oldest message entries from the UI to maintain the limit
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * specified in the consoleLimit configuration.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method _trimOldEntries
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith _trimOldEntries : function () {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith i = entries ? entries.size() - this.get('consoleLimit') : 0;
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith if (i > 0) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith for (;i>=0;--i) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Returns the input string with ampersands (&), <, and > encoded
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * as HTML entities.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method _encodeHTML
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param s {String} the raw string
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @return String the encoded string
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith _encodeHTML : function (s) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Clears the timeout for printing buffered messages.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method _clearTimeout
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith _clearTimeout : function () {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Event handler for clicking on the Pause checkbox to update the paused
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * attribute.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method _onPauseClick
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param e {Event} DOM event facade for the click event
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith _onPauseClick : function (e) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith this.set(PAUSED,paused,{ src: Y.Widget.UI_SRC });
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Event handler for clicking on the Clear button. Pass-through to
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <code>this.clearConsole()</code>.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method _onClearClick
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param e {Event} DOM event facade for the click event
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith _onClearClick : function (e) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Setter method for logLevel attribute. Acceptable values are
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * "error", "warn", "info", and
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Y.Console.LOG_LEVEL_ERROR, Y.Console.LOG_LEVEL_WARN,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Y.Console.LOG_LEVEL_INFO. Any other value becomes
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Y.Console.LOG_LEVEL_INFO.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method _setLogLevel
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param v {String|Number} String or numeric alias for the desired logLevel
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @return Number LOG_LEVEL_ERROR, _WARN, or _INFO
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith _setLogLevel : function (v) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith } else if (!isNumber(v)) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Verifies input logLevel is one of Y.Console.LOG_LEVEL_ERROR,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Y.Console.LOG_LEVEL_WARN, or Y.Console.LOG_LEVEL_INFO.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method _validateNewLogLevel
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param v {Number} requested logLevel
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @return Boolean
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith _validateNewLogLevel : function (v) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Updates the UI if changes are made to any of the strings in the strings
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * attribute.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method _afterStringsChange
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param e {Event} Custom event for the attribute change
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith _afterStringsChange : function (e) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith var prop = e.subAttrName ? e.subAttrName.split(DOT)[1] : null,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith if ((!prop || prop === TITLE) && before.title !== after.title) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith if ((!prop || prop === PAUSE) && before.pause !== after.pause) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith if ((!prop || prop === CLEAR) && before.clear !== after.clear) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Updates the UI and schedules or cancels the scheduled buffer printing
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * operation.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method _afterPausedChange
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param e {Event} Custom event for the attribute change
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith _afterPausedChange : function (e) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith var node = this._foot.queryAll('input[type=checkbox].'+C_PAUSE);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith } else if (this._timeout) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Calls this._trimOldEntries() in response to changes in the configured
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * consoleLimit attribute.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method _afterConsoleLimitChange
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param e {Event} Custom event for the attribute change
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Responds to log events by normalizing qualifying messages and passing
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * them along through the entry event for buffering etc.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method _onLogEvent
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param msg {String} the log message
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param cat {String} OPTIONAL the category or logLevel of the message
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param src {String} OPTIONAL the source of the message (e.g. widget name)
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith if (!this.get(DISABLED) && this._isInLogLevel(msg,cat,src)) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /* TODO: needed? */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith message : this._normalizeMessage.apply(this,arguments)
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Clears the console, resets the startTime attribute, enables and
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * unpauses the widget.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method _defResetFn
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith _defResetFn : function () {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Buffers incoming message objects and schedules the printing.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method _defEntryFn
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param e {Event} The Custom event carrying the message in its payload
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith _defEntryFn : function (e) {