Yahoo! Developer Network Home - Help

YDN Site Search

# 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"); };

### Logger Control Examples:

- Basic Logging
- Configuring LogReader
- Using LogWriter
- Logger Integration with YUI Components
- Skinning Model
- Complex Application (included with examples for Layout Manager (beta))

### More Logger Control Resources:

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

Copyright © 2008 Yahoo! Inc. All rights reserved.

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