My favorites | Sign in
Logo
             
Search
for
Updated Aug 12, 2009 by jason.michael.crist
Labels: Featured
pblogger_examples  
Peanut Butter Logger Instruction & Code Examples

Peanut Butter Logger Instruction

Basic Usage

Creation

The PBLogger should always be instantiated with the public static function getLogger(). Do not create a new instance of the class via new PBLogger()

When an instance of the logger is created/retrieved then you should set the category of the logger. This will be used to determine if a new logger needs to be created (one logger instance will be created for each category). This category can also be used to determine what part of the application the log originated from (for instance the pbcommands library use the "pbking.commands" category). It can also be used to filter which logs you are interested in viewing.

Example:

var logger:PBLogger = PBLogger.getLogger("pbking.examples");

Logging

To log a message simply call one of the five logging commands on the instance of the logger. These log commands/levels are debug, info, error, warning, and fatal.

Example:

logger.debug("this is my message");

This message will be traced in the output console along with the category and level information.

pbking.examples | debug | this is my message

Trace Filtering

By default ALL logs are sent to the console no matter what log level. If you wish to limit the severity of the logs that are traced then you can set the globalTraceLevel. All logs must be a higher number that this to be traced to the console.

Alternately you could set the traceLevel of a specific PBLogger instance to further filter the logs.

These filters effect ONLY what is traced to the console. All logs are always dispatched as events.

Example:

PBLogger.globalTraceLevel = PBLogLevel.INFO;
logger.traceLevel = PBLogLevel.WARN;

Log Event Handling

If you are interested in doing more than just tracing your logs to the console then you can either listen for log events from the log instances or from the PBLogger class which will send you ALL logs passing through the logging framework.

Example:

//captures logs sent to this logger only
logger.addEventListener(PBLogEvent.LOG, onMyLog);

//captures logs sent to ALL loggers
PBLogger.addEventListener(PBLogEvent.LOG, onAllLog);

function onMyLog(e:PBLogEvent):void
{
  if(e.level >= PBLogLevel.WARN)
    sendLogToService(e.toString);
}

Bridges

Sometimes there is a need to hook into another logging framework. Many external logging tools for Flash/Flex have their own logging framework. Sometimes you need to hook an existing project that uses the Flex logging framework into the PBLogger framework. In order to do that we use "bridges".

Arthropod Bridge

Arthropod is the logger I often use to see my logs outside of the console window. A bridge to pass all PBLogger logs into this comes with the library. Initilization is very simple:

PBLogArthropodBridge.initialize();

That's it. All logs sent to the PBLogger framework will be sent (and colored) to the Arthropod viewer.

If you want to set the optional password then just pass it when you initialize:

PBLogArthropodBridge.initialize("pbiscool");

Sign in to add a comment
Hosted by Google Code