Packagenet.user1.logger
Classpublic class Logger
InheritanceLogger Inheritance flash.events.EventDispatcher

Since : Reactor 1.0.0

The Logger class manages Reactor's client-side log, which records client/server communications and events of general interest for the purposes of debugging. To access Reactor's Logger instance, use the Reactor class's getLog() method. For example,
   var reactor:Reactor = new Reactor();
   var log:Logger = reactor.getLog();
   // Add a debugging message to the log:
   log.debug("Testing...1...2...3...");
   
To read the log's history of log entries, use the getHistory() method. To be notified whenever a new message is added to the log, use addEventListener() to register for the LogEvent.UPDATE event. For example,
   var log:Logger = reactor.getLog();
   log.addEventListener(LogEvent.UPDATE, updateListener);
   

To add new messages to the log, use the fatal(), error(), warn(), info(), or debug() methods. An application's most important log messages should be added via fatal(); least important messages should be added via debug(). By default, Reactor uses ActionScript's built-in trace() function to output log entries to the debug console in ActionScript development environments (see the LogTracer class). To stop log messages from being traced in an application, set the Reactor class's traceLogMessages constructor parameter to false.

The following code shows how to output log messages to a custom text field.
   package {
     import flash.display.Sprite; 
     import flash.text.TextField;
   
     import net.user1.logger.LogEvent;
     import net.user1.logger.Logger;
     import net.user1.reactor.Reactor;
   
     public class UTest extends Sprite {
       protected var reactor:Reactor;
       protected var logOutput:TextField;
   
       public function UTest () {
         // Create the log output text field
         logOutput = new TextField();
         logOutput.border = true;
         logOutput.background = true;
         logOutput.width = 500;
         logOutput.height = 300;
         addChild(logOutput);
         
         // Register for log updates
         reactor = new Reactor();
         reactor.getLog().setLevel(Logger.DEBUG);
         reactor.getLog().addEventListener(LogEvent.UPDATE, logUpdateListener);
         reactor.getLog().debug("Hello world!");
       }
   
       public function logUpdateListener (e:LogEvent):void {
         logOutput.appendText(e.getTimeStamp() + " "
                              + e.getLevel() + ": " 
                              + e.getMessage() + "\n");
         logOutput.scrollV = logOutput.maxScrollV;
       }
     }
   }
   

See also

LogEvent
net.user1.reactor.Reactor.getLog()


Public Methods
 MethodDefined By
  
Logger(historyLength:uint = 100)
Constructor
Logger
  
addSuppressionTerm(term:String):void
Forces the log to ignore entries containing the specified term.
Logger
  
debug(msg:String):void
Sends a message to the log, with severity "DEBUG".
Logger
  
Hides the time stamp on subsequent messages.
Logger
  
Adds a time stamp to all subsequent messages.
Logger
  
error(msg:String):void
Sends a message to the log, with severity "ERROR".
Logger
  
fatal(msg:String):void
Sends a message to the log, with severity "FATAL".
Logger
  
getHistory():Array
Returns all messages in the log's history.
Logger
  
Returns the number of messages that are kept in the log's history.
Logger
  
getLevel():String
Returns the human-readable message filter level for the log.
Logger
  
info(msg:String):void
Sends a message to the log, with severity "INFO".
Logger
  
removeSuppressionTerm(term:String):Boolean
Instructs the log to stop ignoring entries containing the specified term.
Logger
  
setHistoryLength(newHistoryLength:uint):void
Specifies the number of messages that should be kept in the log's history.
Logger
  
setLevel(level:String):void
Sets the message filter level for the log.
Logger
  
warn(msg:String):void
Sends a message to the log, with severity "WARN".
Logger
Events
 Event Summary Defined By
   Dispatched when the log's level is changed via Logger's setLevel() method.Logger
   Dispatched when a new message is added to the log.Logger
Public Constants
 ConstantDefined By
  DEBUG : String = DEBUG
[static]
Logger
  ERROR : String = ERROR
[static]
Logger
  FATAL : String = FATAL
[static]
Logger
  INFO : String = INFO
[static]
Logger
  WARN : String = WARN
[static]
Logger
Constructor Description
Logger()Constructor
public function Logger(historyLength:uint = 100)

Since : Reactor 1.0.0

Constructor

Parameters
historyLength:uint (default = 100) — The number of log messages that should be stored in the log history. Defaults to 100.
Method Descriptions
addSuppressionTerm()method
public function addSuppressionTerm(term:String):void

Since : Reactor 1.0.0

Forces the log to ignore entries containing the specified term.

Parameters

term:String — The term to match.

debug()method 
public function debug(msg:String):void

Since : Reactor 1.0.0

Sends a message to the log, with severity "DEBUG".

Parameters

msg:String

disableTimeStamp()method 
public function disableTimeStamp():void

Since : Reactor 1.0.0

Hides the time stamp on subsequent messages.

enableTimeStamp()method 
public function enableTimeStamp():void

Since : Reactor 1.0.0

Adds a time stamp to all subsequent messages.

error()method 
public function error(msg:String):void

Since : Reactor 1.0.0

Sends a message to the log, with severity "ERROR".

Parameters

msg:String

fatal()method 
public function fatal(msg:String):void

Since : Reactor 1.0.0

Sends a message to the log, with severity "FATAL".

Parameters

msg:String

getHistory()method 
public function getHistory():Array

Since : Reactor 1.0.0

Returns all messages in the log's history.

Returns
Array
getHistoryLength()method 
public function getHistoryLength():uint

Since : Reactor 1.0.0

Returns the number of messages that are kept in the log's history. Defaults to 100.

Returns
uint
getLevel()method 
public function getLevel():String

Since : Reactor 1.0.0

Returns the human-readable message filter level for the log.

Returns
String

See also

setLevel()
info()method 
public function info(msg:String):void

Since : Reactor 1.0.0

Sends a message to the log, with severity "INFO".

Parameters

msg:String

removeSuppressionTerm()method 
public function removeSuppressionTerm(term:String):Boolean

Since : Reactor 1.0.0

Instructs the log to stop ignoring entries containing the specified term.

Parameters

term:String — The term to match.

Returns
Boolean — true if the term was removed; false if the term was not found.
setHistoryLength()method 
public function setHistoryLength(newHistoryLength:uint):void

Since : Reactor 1.0.0

Specifies the number of messages that should be kept in the log's history.

Parameters

newHistoryLength:uint

setLevel()method 
public function setLevel(level:String):void

Since : Reactor 1.0.0

Sets the message filter level for the log. The supplied level must be one of the following Logger constants: Logger.FATAL, Logger.ERROR, Logger.WARN, Logger.INFO, or Logger.DEBUG. Log levels are ranked in order, with FATAL being most severe and DEBUG being least severe. Messages that are less severe than the filter level set via setLevel() are excluded from the log. For example, if the filter level is set to Logger.DEBUG, all messages are included in the log. If the filter level is set to Logger.WARN, messages sent via Logger's debug() and info() methods are excluded from the log, but messages sent via Logger's error(), warn(), and fatal() methods are included in the log. The default log level is Logger.INFO (exclude DEBUG messages only).

Reactor's log level can also be set an external configuration file. For details, see the Reactor class constructor's configURL parameter.

Parameters

level:String — The level dictating which messages are filtered out. Must be one of the filter levels defined as static constants by the Logger class. Messages less severe than the specified level are excluded from the log.

See also

warn()method 
public function warn(msg:String):void

Since : Reactor 1.0.0

Sends a message to the log, with severity "WARN".

Parameters

msg:String

Event Detail
LEVEL_CHANGE Event
Event Object Type: LogEvent
LogEvent.type variable = net.user1.logger.LogEvent.LEVEL_CHANGE

Dispatched when the log's level is changed via Logger's setLevel() method. To access the new level, use getLevel(), which returns one of the following values: Logger.FATAL, Logger.ERROR, Logger.WARN, Logger.INFO, or Logger.DEBUG.

See also

UPDATE Event  
Event Object Type: LogEvent
LogEvent.type variable = net.user1.logger.LogEvent.UPDATE

Dispatched when a new message is added to the log. To add a message to the log, use one of the following Logger class methods: debug(), info(), warn(), error(), or fatal().

See also

Constant Descriptions
DEBUGConstant
public static const DEBUG:String = DEBUG

ERRORConstant 
public static const ERROR:String = ERROR

FATALConstant 
public static const FATAL:String = FATAL

INFOConstant 
public static const INFO:String = INFO

WARNConstant 
public static const WARN:String = WARN