YUI Library Home

Site Search (YDN & YUIBlog):

# YUI Library Examples: Logger Control: Using LogWriter

# Logger Control: Using LogWriter

Using LogWriter.

#### Example: Log messages into different categories

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

- Log an "info" message.
- Log a "warn" message.
- Log an "error" message.
- Log a "time" message.

#### 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()`.

- Log an "info" message.
- Log a "warn" message.
- Log an "error" message.
- Log a "time" message.

#### 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.

- Log an "info" message.
- Log a "warn" message.
- Log an "error" message.
- Log a "time" message.

## Sample Code for this Example

CSS:

/* custom styles for this example */ #container {position:relative;float:right;margin:1em;} #container .mytype {background-color:#FF99CC;}

Markup:

<div id="container"></div>

JavaScript:

YAHOO.example.LogWriter = new function() { this.myLogReader = new YAHOO.widget.LogReader("container"); this.myLogWriter = new YAHOO.widget.LogWriter("MyClass"); // Generate logs YAHOO.log("This is an info message.", "info", source); YAHOO.log("This is a warn message.", "warn", source); YAHOO.log("This is an error message.", "error", source); YAHOO.log("This is a time message.", "time", source); this.myLogWriter.log("This is an info message.", "info"); this.myLogWriter.log("This is a warn message.", "warn"); this.myLogWriter.log("This is an error message.", "error"); this.myLogWriter.log("This is a time message.", "time"); };

## 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.

### Logger Control Examples:

### More Logger Control Resources:

- User's Guide (external)
- API Documentation
- Cheat Sheet PDF (external)

Copyright © 2009 Yahoo! Inc. All rights reserved.

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