1  /*
     2   * Copyright the original author or authors.
     3   * 
     4   * Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   * 
     8   *      http://www.mozilla.org/MPL/MPL-1.1.html
     9   * 
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  import org.as2lib.env.log.handler.XmlSocketHandler;
    18  import org.as2lib.util.Stringifier;
    19  import org.as2lib.env.log.stringifier.SosMessageStringifier;
    20  
    21  /**
    22   * {@code SosHandler} uses the {@code XMLSocket} to log the message to
    23   * POWERFLASHER's SOS XML-Socket-Server.
    24   * 
    25   * <p>It logs colorized and formatted debug information to POWERFLASHER's SOS
    26   * XML-Socket-Server
    27   * 
    28   * @author Christoph Atteneder
    29   * @see <a href="http://sos.powerflasher.com">SOS - SocketOutputServer</a>
    30   */
    31  class org.as2lib.env.log.handler.SosHandler extends XmlSocketHandler {
    32  	
    33  	/** Color of debug messages. */
    34  	private static var DEBUG:Number = 0xFFFFFF;
    35  	
    36  	/** Key of debug messages. */
    37  	public static var DEBUG_KEY:String = "DEBUG";
    38  	
    39  	/** Color of info messages. */
    40  	private static var INFO:Number = 0xD9D9FF;
    41  	
    42  	/** Key of info messages. */
    43  	public static var INFO_KEY:String = "INFO";
    44  	
    45  	/** Color of warning messages. */
    46  	private static var WARNING:Number = 0xFFFFCE;
    47  	
    48  	/** Key of warning messages. */
    49  	public static var WARNING_KEY:String = "WARNING";
    50  	
    51  	/** Color of error messages. */
    52  	private static var ERROR:Number = 0xFFBBBB;
    53  	
    54  	/** Key of error messages. */
    55  	public static var ERROR_KEY:String = "ERROR";
    56  	
    57  	/** Color of fatal messages. */
    58  	private static var FATAL:Number = 0xCC99CC;
    59  	
    60  	/** Key of fatal messages. */
    61  	public static var FATAL_KEY:String = "FATAL";
    62  	
    63  	/**
    64  	 * Constructs a new {@code SosHandler} instance.
    65  	 * 
    66  	 * <p>If {@code messageStringifier} is not specified an instance of class
    67  	 * {@link SosMessageStringifier} will be used.
    68  	 * 
    69  	 * @param messageStringifier (optional) the log message stringifier to use
    70  	 */
    71  	public function SosHandler(messageStringifier:Stringifier) {
    72  		super("localhost", 4445, (!messageStringifier ? new SosMessageStringifier() : messageStringifier));
    73  		socket.send("<setKey><name>" + DEBUG_KEY + "</name><color>" + DEBUG + "</color></setKey>");
    74  		socket.send("<setKey><name>" + INFO_KEY + "</name><color>" + INFO + "</color></setKey>");
    75  		socket.send("<setKey><name>" + WARNING_KEY + "</name><color>" + WARNING + "</color></setKey>");
    76  		socket.send("<setKey><name>" + ERROR_KEY + "</name><color>" + ERROR + "</color></setKey>");
    77  		socket.send("<setKey><name>" + FATAL_KEY + "</name><color>" + FATAL + "</color></setKey>");
    78  	}
    79  	
    80  }