YUI Library Examples: Logger Control: Using LogWriter

Logger Control: Using LogWriter

Using LogWriter.

Logger Console

INFO0ms (+0) 3:32:56 AM:

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 | ?

Copyright © 2008 Yahoo! Inc. All rights reserved.

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