console.js revision f9918f6b658319940d633dd8c9a2c16d05b4c881
'<div class="{entry_class} {cat_class} {src_class}">'+
'<p class="{entry_meta_class}">'+
'<span class="{entry_src_class}">'+
'<span class="{entry_cat_class}">'+
'<span class="{entry_time_class}">'+
' {totalTime}ms (+{elapsedTime}) {localTime}'+
'<pre class="{entry_content_class}">{message}</pre>'+
* The identity of the widget. * Static identifier for logLevel configuration setting to allow all * incoming messages to generate Console entries. * @property Console.LOG_LEVEL_INFO * Static identifier for logLevel configuration setting to allow only * incoming messages of logLevel "warn" or "error" * to generate Console entries. * @property Console.LOG_LEVEL_WARN * Static identifier for logLevel configuration setting to allow only * incoming messages of logLevel "error" to generate * @property Console.LOG_LEVEL_ERROR * Map (object) of classNames used to populate the placeholders in the * Console.ENTRY_TEMPLATE markup when rendering a new Console entry. * <p>By default, the keys contained in the object are:</p> * <li>entry_meta_class</li> * <li>entry_cat_class</li> * <li>entry_src_class</li> * <li>entry_time_class</li> * <li>entry_content_class</li> * @property Console.ENTRY_CLASSES * 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. * <p>By default, the keys contained in the object are:</p> * <li>console_hd_class</li> * <li>console_bd_class</li> * <li>console_ft_class</li> * <li>console_controls_class</li> * <li>console_checkbox_class</li> * <li>console_pause_class</li> * <li>console_pause_label_class</li> * <li>console_button_class</li> * <li>console_clear_class</li> * <li>console_collapse_class</li> * <li>console_title_class</li> * @property Console.CHROME_CLASSES * Markup template used to generate the DOM structure for the header * section of the Console when it is rendered. The template includes * <li>console_button_class - contributed by Console.CHROME_CLASSES</li> * <li>console_collapse_class - contributed by Console.CHROME_CLASSES</li> * <li>console_hd_class - contributed by Console.CHROME_CLASSES</li> * <li>console_title_class - contributed by Console.CHROME_CLASSES</li> * <li>str_collapse - pulled from attribute strings.collapse</li> * <li>str_title - pulled from attribute strings.title</li> * @property Console.HEADER_TEMPLATE '<div class="{console_hd_class}">'+
'<h4 class="{console_title_class}">{str_title}</h4>'+
'<button type="button" class="'+
'{console_button_class} {console_collapse_class}">{str_collapse}'+
* 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. * @property Console.BODY_TEMPLATE * Markup template used to generate the DOM structure for the footer * section of the Console when it is rendered. The template includes * many of the {placeholder}s from Console.CHROME_CLASSES as well as: * <li>id_guid - generated unique id, relates the label and checkbox</li> * <li>str_pause - pulled from attribute strings.pause</li> * <li>str_clear - pulled from attribute strings.clear</li> * @property Console.FOOTER_TEMPLATE '<div class="{console_ft_class}">'+
'<div class="{console_controls_class}">'+
'<label for="{id_guid}" class="{console_pause_label_class}">'+
'<input type="checkbox" class="{console_checkbox_class} '+
'{console_pause_class}" value="1" id="{id_guid}"> '+
'<button type="button" class="'+
'{console_button_class} {console_clear_class}">{str_clear}'+
* 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: * <li>sourceAndDetail</li> * @property Console.ENTRY_TEMPLATE * Static property used to define the default attribute configuration of * @property Console.ATTRS * Name of the custom event that will communicate log messages. * Object that will emit the log events. By default the YUI instance. * To have a single Console capture events from all YUI instances, set * this to the Y.Global object. * Collection of strings used to label elements in the Console UI. * Default collection contains the following name:value pairs: * <li>title : "Log Console"</li> * <li>pause : "Pause"</li> * <li>clear : "Clear"</li> * <li>collapse : "Collapse"</li> * <li>expand : "Expand"</li> * Boolean to pause the outputting of new messages to the console. * When paused, messages will accumulate in the buffer. * If a category is not specified in the Y.log(..) statement, this * category will be used. Categories "info", * "warn", and "error" are also called log level. * @attribute defaultCategory * If a source is not specified in the Y.log(..) statement, this * @attribute defaultSource * Markup template used to create the DOM structure for Console entries. * @attribute entryTemplate * @default Console.ENTRY_TEMPLATE * 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 their corresponding statics * Console.LOG_LEVEL_INFO and so on. * @default Y.config.logLevel or Console.LOG_LEVEL_INFO * Millisecond timeout between iterations of the print loop, moving * entries from the buffer to the UI. * @attribute printTimeout * Maximum number of entries printed in each iteration of the print * loop. This is used to prevent excessive logging locking the page UI. * 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. * @attribute consoleLimit * New entries should display at the top of the Console or the bottom? * When new entries are added to the Console UI, should they be * @attribute scrollIntoView * The baseline time for this Console instance, used to measure elapsed * time from the moment the console module is <code>use</code>d to the * moment each new entry is logged (not rendered). * This value is reset by the instance method myConsole.reset(). * @default The moment the console module is <code>use</code>d * The precise time the last entry was logged. Used to measure elapsed * time between log messages. * @default The moment the console module is <code>use</code>d * Controls the collapsed state of the Console * String with units, or number, representing the height of the Console, * inclusive of header and footer. If a number is provided, the default * unit, defined by Widget's DEF_UNIT, property is used. * @type {String | Number} * String with units, or number, representing the width of the Console. * If a number is provided, the default unit, defined by Widget's * DEF_UNIT, property is used. * @type {String | Number} * Pass through to the YUI instance useBrowserConsole configuration. * By default this is set to false, which will disable logging to the * browser console when a Console instance is created. If the * logSource is not a YUI instance, this has no effect. * @attribute useBrowserConsole * Allows the Console to flow in the document. Available values are * 'inline', 'block', and 'separate' (the default). * Category to prefix all event subscriptions to allow for ease of detach * Reference to the Node instance containing the header contents. * Reference to the Node instance that will house the console messages. * Reference to the Node instance containing the footer contents. * Holds the object API returned from <code>Y.later</code> for the print * Array of normalized message objects awaiting printing. * Wrapper for <code>Y.log</code>. * @param arg* {MIXED} (all arguments passed through to <code>Y.log</code>) * Clear the console of messages and flush the buffer of pending messages. // TODO: clear event listeners from console contents * Clears the console and resets internal timers. * Collapses the body and footer. * Expands the body and footer if collapsed. * Outputs buffered messages to the console UI. This is typically called * from a scheduled interval until the buffer is empty (referred to as the * print loop). The number of buffered messages output to the Console is * limited to the number provided as an argument. If no limit is passed, * all buffered messages are rendered. * @param limit {Number} (optional) max number of buffered entries to write // turn off logging system if (
this.
get(
'scrollIntoView')) {
// restore logging system * Constructor code. Set up the buffer and entry template, publish * internal events, and subscribe to the configured logEvent. this.
get(
'logEvent'),Y.
bind(
"_onLogEvent",
this));
* Transfers a received message to the print loop buffer. Default * behavior defined in _defEntryFn. * @param event {Event.Facade} An Event Facade object with the following attribute specific properties added: * <dd>The message data normalized into an object literal (see _normalizeMessage)</dd> * @preventable _defEntryFn * Triggers the reset behavior via the default logic in _defResetFn. * @param event {Event.Facade} Event Facade object * @preventable _defResetFn * Tears down the instance, flushing event subscriptions and purging the UI. var bb =
this.
get(
'boundingBox');
* Generate the Console UI. // Apply positioning to the bounding box if appropriate * Sync the UI state to the current attribute state. * Set up event listeners to wire up the UI to the internal state. * Create the DOM structure for the header elements. * Create the DOM structure for the console body—where messages are * Create the DOM structure for the footer elements. * Determine if incoming log messages are within the configured logLevel * to be buffered for printing. * Create a log entry message from the inputs including the following keys: * <li>time - this moment</li> * <li>message - leg message</li> * <li>category - logLevel or custom category for the message</li> * <li>source - when provided, the widget or util calling Y.log</li> * <li>sourceAndDetail - same as source but can include instance info</li> * <li>localTime - readable version of time</li> * <li>elapsedTime - ms since last entry</li> * <li>totalTime - ms since Console was instantiated or reset</li> * @method _normalizeMessage * @param e {Event} custom event containing the log message * @return Object the message object // Extract m.source "Foo" from m.sourceAndDetail "Foo bar baz" * Sets an interval for buffered messages to be output to the console. this.
get(
'printTimeout'),
this.
get(
'printLimit'),
true);
* Translates message meta into the markup for a console entry. * @method _createEntryHTML * @param m {Object} object literal containing normalized message metadata return this.
get(
'entryTemplate').
replace(/\{(\w+)\}/g,
* Scrolls to the most recent entry * Performs HTML escaping on strings in the message object. * @method _htmlEscapeMessage * @param m {Object} the normalized message object * @return Object the message object with proper escapement * Removes the oldest message entries from the UI to maintain the limit * specified in the consoleLimit configuration. * @method _trimOldEntries // Turn off the logging system for the duration of this operation // to prevent an infinite loop if (
this.
get(
'newestOnTop')) {
* Returns the input string with ampersands (&), <, and > encoded * @param s {String} the raw string * @return String the encoded string * Clears the timeout for printing buffered messages. * @method _cancelPrintLoop * Validates input value for style attribute. Accepts only values 'inline', * 'block', and 'separate'. * @param style {String} the proposed value * Event handler for clicking on the Pause checkbox to update the paused * @param e {Event} DOM event facade for the click event * Event handler for clicking on the Clear button. Pass-through to * <code>this.clearConsole()</code>. * @param e {Event} DOM event facade for the click event * "collapsed" attribute accordingly. * @method _onCollapseClick * @param e {Event} DOM event facade for the click event * Setter method for logLevel attribute. Acceptable values are * "error", "warn", and "info" (case * insensitive). Other values are treated as "info". * @param v {String} the desired log level * @return String One of Console.LOG_LEVEL_INFO, _WARN, or _ERROR * Set the height of the Console container. Set the body height to the difference between the configured height and the calculated heights of the header and footer. * Overrides Widget.prototype._uiSetHeight. * @param v {String|Number} the new height var h =
this.
get(
'boundingBox').
get(
'offsetHeight') -
* Updates the UI if changes are made to any of the strings in the strings * @method _afterStringsChange * @param e {Event} Custom event for the attribute change * Updates the UI and schedules or cancels the print loop. * @method _afterPausedChange * @param e {Event} Custom event for the attribute change * Checks or unchecks the paused checkbox * @method _uiUpdatePaused * @param on {Boolean} the new checked state * Calls this._trimOldEntries() in response to changes in the configured * consoleLimit attribute. * @method _afterConsoleLimitChange * @param e {Event} Custom event for the attribute change * Updates the className of the contentBox, which should trigger CSS to * hide or show the body and footer sections depending on the new value. * @method _afterCollapsedChange * @param e {Event} Custom event for the attribute change * Updates the UI to reflect the new Collapsed state * @method _uiUpdateCollapsed * @param v {Boolean} true for collapsed, false for expanded var bb =
this.
get(
'boundingBox'),
method = v ?
'addClass' :
'removeClass',
str =
this.
get(
'strings.'+(v ?
'expand' :
'collapse'));
* Makes adjustments to the UI if needed when the Console is hidden or shown * @method _afterVisibleChange * @param e {Event} the visibleChange event * Recalculates dimensions and updates appropriately when shown * @method _uiUpdateFromHideShow * @param v {Boolean} true for visible, false for hidden * Responds to log events by normalizing qualifying messages and passing * them along through the entry event for buffering etc. * @param msg {String} the log message * @param cat {String} OPTIONAL the category or logLevel of the message * @param src {String} OPTIONAL the source of the message (e.g. widget name) * Clears the console, resets the startTime attribute, enables and * Buffers incoming message objects and schedules the printing. * @param e {Event} The Custom event carrying the message in its payload