The Logger Control provides a simple way to read or write log messages with
a single line of code. With this control, you can tap into the rich
event-driven messages included with the YUI Library's debug files; This
messaging allows you to get a fuller picture of the inner workings of any YUI
Library component. The Logger Control provides a simple messaging interface
that allows you to filter, pause, resume, and clear log messages on your
screen. Whether or not you invoke this UI, you can monitor log output via the
FireBug extension for Firefox or via the Safari JavaScript console. The Logger Control supports
logging messages with customizable categories and
sources. Adventurous developers can extend Logger to build their own
implementations to suit any requirement.
To use the Logger component, include the following source files in your web page with the script tag:
Instead of copying and pasting the filepaths above, try letting the YUI dependency Configurator determine the optimal file list for your desired components; the Configurator uses YUI Loader write out the full HTML for including the precise files you need for your implementation.
Note: If you wish to include this component via the YUI Loader, its module name is logger. (Click here for the full list of module names for YUI Loader.)
Where these files come from: The files included using the text above will be served from Yahoo! servers; see "Serving YUI Files from Yahoo!" for important information about this service. JavaScript files are minified, meaning that comments and white space have been removed to make them more efficient to download. To use the full, commented versions or the -debug versions of YUI JavaScript files, please download the library distribution and host the files on your own server.
Order matters: As is the case generally with JavaScript and CSS, order matters; these files should be included in the order specified above. If you include files in the wrong order, errors may result.
Using "CSS skins": One of the files listed above contains a CSS "skin" for the Logger Control. For this skin CSS to work correctly, you will need to apply the CSS class "yui-skin-sam" to an element that is a parent of the element in which the component lives. You can usually accomplish this simply by putting the class on the <body> tag:
<body class="yui-skin-sam">
For more information on skinning YUI components and making use of default skins, see our Understanding YUI Skins article here on the website.
Instantiate a LogReader to display log messages on your web page:
Attach a LogReader to a specific HTML element by passing the element's ID to Logger's constructor:
Attach a LogReader to a specific HTML element by passing an element reference to Logger's constructor:
Use the YAHOO.log() function, part of the Yahoo Global Object, to write log messages from anywhere in your code:
Assign a category to your log message:
Assign a custom category to your log message:
Assign a category and a source to your log message:
This section describes in more detail the Logger, LogReader, and LogWriter classes, as well as some common configuration cases.
YAHOO.widget.Logger is a singleton class that manages incoming log messages and makes them
available for output to LogReader instances. By setting the Logger property
maxStackEntries, you can cap the number of log messages the Logger will manage.
Once the limit is reached, the oldest log message will be evicted to make room
for the newer entry.
Some browsers have implemented a
global console.log() method which can serve various functionalities. For instance,
if you have the FireBug extension to Firefox installed, or the Safari JavaScript
console enabled, logging messages to console.log() will output to browser-specific components.
By default, the YUI Logger does not call this method, but you may wish
enable this feature by calling YAHOO.widget.Logger.enableBrowserConsole(). Once enabled,
calling YAHOO.widget.Logger.disableBrowserConsole() will disable this feature.
The Logger class also allows you to clear out all previous log messages:
YAHOO.widget.LogReader class creates a standalone UI control on
a web page to easily display Logger messages included with debug builds of the YUI
Library. LogReaders allow you to take full advantage of features like filtration
by category and by source. The LogReader interface also allows you to pause and
resume logging during script execution. Although LogReader has been
pre-defined with a modestly configurable look and feel, advanced implementers
may fully customize LogReader's CSS or subclass LogReader entirely for a
customized experience.
Visibility of the LogReader UI is controlled using calls to show() and hide(). By default, the LogReader is visible.
The following properties are configurable using an object literal to set values in the constructor:
The LogReader class allows you to customize the output format of log messages in three ways:
verboseOutput toggles between the default verbose and compact formatsentryFormat assigns a format template used to generate the entries' innerHTML stringsformatMsg method can be overridden with custom codeentryFormat TemplatesentryFormat templates can contain markup as well as any of the following bracketed placeholders:
For example, the template used for verbose log entries (the default setting), is:
formatMsgThe YAHOO.widget.LogWriter class provides a shortcut for implementers who are logging many
messages from the same source. For instance, if you are debugging a class
written in JavaScript, you may want to instantiate a single LogWriter to write
logs for the entire class:
Note that when you supply a space-delimited string to the LogWriter constructor, the first word of the string will be used to assign a source to the log message, and the rest of the string will be prepended to the log message for supplementary detail. LogReader will parse the string at the first empty space character. If there are no empty spaces in the string, the entire string will be used to assign a source to the log message.
The Logger comes with a default presentation or "skin," part of the "Sam Skin" visual treatment that accompanies most YUI controls. You can read more about the general approach to skinning YUI components in this in-depth article.
In the case of the Logger Control, there is no "core" CSS treatment — which is to say that there is no CSS that is considered essential to the functioning of the control. All of the CSS provided with Logger is part of the Sam Skin visual treatment.

To explore the CSS which controls the Logger's presentation, please review the Logger Skinning Example wherein the full CSS for the control is displayed.
About this Section: YUI generally works well with mobile browsers that are based on A-Grade browser foundations. For example, Nokia's N-series phones, including the N95, use a browser based on Webkit — the same foundation shared by Apple's Safari browser, which is found on the iPhone. The fundamental challenges in developing for this emerging class of full, A-Grade-derived browsers on handheld devices are:
There are other considerations, many of them device/browser specific (for example, current versions of the iPhone's Safari browser do not support Flash). The goal of these sections on YUI User's Guides is to provide you some preliminary insights about how specific components perform on this emerging class of mobile devices. Although we have not done exhaustive testing, and although these browsers are revving quickly and present a moving target, our goal is to provide some early, provisional advice to help you get started as you contemplate how your YUI-based application will render in the mobile world.
More Information:
The Logger control has been tested on several high-end smart phones without any major known issues. It is meant primarily as a development tool, and therefore it is not recommended in production environments. Due to the inherent limitations found in mobile platforms, implementers should take into account the following preliminary list of known issues:
console.log() function may be unreliable at
best or altogether non-existent.The YUI Library and related topics are discussed on the on the ydn-javascript mailing list.
In addition, please visit the YUIBlog for updates and articles about the YUI Library written by the library's developers.
The YUI Library's public bug tracking and feature request repositories are located on the YUI SourceForge project site. Before filing new feature requests or bug reports, please review our reporting guidelines.














Copyright © 2008 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Copyright Policy - Job Openings