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.util.Stringifier;
    18  import org.as2lib.env.log.LogHandler;
    19  import org.as2lib.env.log.LogMessage;
    20  import org.as2lib.env.log.handler.AbstractLogHandler;
    21  
    22  import com.interactiveAlchemy.utils.Debug;
    23  
    24  /**
    25   * {@code DebugItHandler} uses {@code com.interactiveAlchemy.utils.Debug.write} of the
    26   * DebugIt Component from Robert Hoekman to log messages.
    27   * 
    28   * @author Simon Wacker
    29   * @see org.as2lib.env.log.logger.DebugItLogger
    30   * @see <a href="http://www.rhjr.net/blog/2005/03/debugit-10.html">DebugIt Component</a>
    31   */
    32  class org.as2lib.env.log.handler.DebugItHandler extends AbstractLogHandler implements LogHandler {
    33  	
    34  	/** Holds a debugIt handler instance. */
    35  	private static var debugItHandler:DebugItHandler;
    36  	
    37  	/**
    38  	 * Returns an instance of this class.
    39  	 *
    40  	 * <p>This method always returns the same instance.
    41  	 *
    42  	 * <p>The {@code messageStringifier} argument is only recognized on first
    43  	 * invocation of this method.
    44  	 * 
    45  	 * @param messageStringifier (optional) the log message stringifier to be used by
    46  	 * the returned handler
    47  	 * @return a debugIt handler
    48  	 */
    49  	public static function getInstance(messageStringifier:Stringifier):DebugItHandler {
    50  		if (!debugItHandler) debugItHandler = new DebugItHandler(messageStringifier);
    51  		return debugItHandler;
    52  	}
    53  	
    54  	/**	
    55  	 * Constructs a new {@code DebugItHandler} instance.
    56  	 *
    57  	 * <p>You can use one and the same instance for multiple loggers. So think about
    58  	 * using the handler returned by the static {@link #getInstance} method. Using this
    59  	 * instance prevents the instantiation of unnecessary debugIt handlers and saves
    60  	 * storage.
    61  	 * 
    62  	 * @param messageStringifier (optional) the log message stringifier to use
    63  	 */
    64  	public function DebugItHandler(messageStringifier:Stringifier) {
    65  		super (messageStringifier);
    66  	}
    67  	
    68  	/**
    69  	 * Writes the passed-in {@code message} using the {@code Debug.write} method.
    70  	 *
    71  	 * <p>The string representation of the {@code message} to log is obtained via
    72  	 * the {@code convertMessage} method.
    73  	 * 
    74  	 * @param message the message to log
    75  	 */
    76  	public function write(message:LogMessage):Void {
    77  		Debug.write(convertMessage(message));
    78  	}
    79  	
    80  }