# Logger Widget :: Writing Logs

### Writing Logs

The following examples demonstrate how to assign different categories and sources to your log messages.

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

#### Sample Code

YAHOO.log("This is an \"info\" message.", "info"); // or just YAHOO.log("This is an \"info\" message."); YAHOO.log("This is a \"warn\" message.", "warn"); YAHOO.log("This is an \"error\" message.", "error"); YAHOO.log("This is a \"time\" message.", "time");

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

#### Sample Code

YAHOO.log("This is an \"info\" message.", "info", "myBucket"); YAHOO.log("This is a \"warn\" message.", "warn", "myBucket"); YAHOO.log("This is an \"error\" message.", "error", "myBucket"); YAHOO.log("This is a \"time\" message.", "time", "myBucket");

#### Example: Create a LogWriter 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

var myLogWriter = new YAHOO.widget.LogWriter("MyClass"); myLogWriter.log("This is an \"info\" message.", "info"); // or just myLogWriter.log("This is an \"info\" message."); myLogWriter.log("This is a \"warn\" message."); myLogWriter.log("This is an \"error\" message."); myLogWriter.log("This is a \"time\" message.");