YUI recommends YUI 3.

YUI 2 has been deprecated since 2011. This site acts as an archive for files and documentation.

YUI Library Home

YUI Library Examples: Logger Control: Using LogWriter

Logger Control: Using LogWriter

Using LogWriter.

Logger Console

INFO 166ms (+128) 12:21:02 PM:

LogReader instance0

LogReader initialized

INFO 38ms (+0) 12:21:02 PM:

Get

Appending node: ../../../2.x/build/event-mouseenter/event-mouseenter-min.js

INFO 38ms (+0) 12:21:02 PM:

Get

attempting to load ../../../2.x/build/event-mouseenter/event-mouseenter-min.js

INFO 38ms (+38) 12:21:02 PM:

Get

_next: q0, loaded: undefined

INFO 0ms (+0) 12:21:02 PM:

global

Logger initialized

Example: Log messages into different categories

By default, unsourced log messages get assigned to a "global" bucket.

Example: Log messages into different categories and assign them to a source called myBucket

You can assign a source to a log message by passing it in as the third argument to YAHOO.log().

Example: Create a LogWriter to write log messages from a class named MyClass

If you plan to assign many log messages to the same source (such as from a class), it may be easier to write log messages from a LogWriter instance.

Sample Code for this Example

CSS:

1/* custom styles for this example */ 
2#container {position:relative;float:right;margin:1em;} 
3#container .mytype {background-color:#FF99CC;} 
view plain | print | ?

Markup:

1<div id="container"></div> 
view plain | print | ?

JavaScript:

1YAHOO.example.LogWriter = new function() { 
2    this.myLogReader = new YAHOO.widget.LogReader("container"); 
3    this.myLogWriter = new YAHOO.widget.LogWriter("MyClass"); 
4 
5    // Generate logs 
6    YAHOO.log("This is an info message.""info", source); 
7    YAHOO.log("This is a warn message.""warn", source); 
8    YAHOO.log("This is an error message.""error", source); 
9    YAHOO.log("This is a time message.""time", source); 
10 
11    this.myLogWriter.log("This is an info message.""info"); 
12    this.myLogWriter.log("This is a warn message.""warn"); 
13    this.myLogWriter.log("This is an error message.""error"); 
14    this.myLogWriter.log("This is a time message.""time"); 
15}; 
view plain | print | ?

Configuration for This Example

You can load the necessary JavaScript and CSS for this example from Yahoo's servers. Click here to load the YUI Dependency Configurator with all of this example's dependencies preconfigured.

Copyright © 2011 Yahoo! Inc. All rights reserved.

Privacy Policy - Terms of Service - Copyright Policy - Job Openings