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.LogMessage;
    19  import org.as2lib.env.log.LogLevel;
    20  import org.as2lib.env.log.level.AbstractLogLevel;
    21  import org.as2lib.env.log.stringifier.PatternLogMessageStringifier;
    22  import org.as2lib.env.log.handler.SosHandler;
    23  
    24  /**
    25   * {@code SosMessageStringifier} stringifies {@link LogMessage} instances into SOS
    26   * compatible log output.
    27   * 
    28   * @author Christoph Atteneder
    29   * @see <a href="http://sos.powerflasher.com">SOS - SocketOutputServer</a>
    30   */
    31  class org.as2lib.env.log.stringifier.SosMessageStringifier extends PatternLogMessageStringifier implements Stringifier {
    32  	
    33  	/**
    34  	 * Constructs a new {@code SosMessageStringifier} instance.
    35  	 */
    36  	public function SosMessageStringifier(Void) {
    37  		super(false, true);
    38  	}
    39  	
    40  	/**
    41  	 * Stringifies {@link LogMessage} instances.
    42  	 * 
    43  	 * @param target the {code LogMessage} instance to stringify
    44  	 * @return the string representation of the given {@code target}
    45  	 */
    46  	public function execute(target):String {
    47  		var message:LogMessage = target;
    48  		var level:LogLevel = message.getLevel();
    49  		var levelKey:String;
    50  		switch(level){
    51  			case AbstractLogLevel.DEBUG:
    52  				levelKey = SosHandler.DEBUG_KEY;
    53  				break;
    54  			case AbstractLogLevel.ERROR:
    55  				levelKey = SosHandler.ERROR_KEY;
    56  				break;
    57  			case AbstractLogLevel.INFO:
    58  				levelKey = SosHandler.INFO_KEY;
    59  				break;
    60  			case AbstractLogLevel.WARNING:
    61  				levelKey = SosHandler.WARNING_KEY;
    62  				break;		
    63  			case AbstractLogLevel.FATAL:
    64  				levelKey = SosHandler.FATAL_KEY;
    65  				break;
    66  			default :
    67  				levelKey = SosHandler.DEBUG_KEY; 
    68  		};
    69  		return "<showMessage key='" + levelKey + "'>" + super.execute(target) + "</showMessage>\n";
    70  	}
    71  	
    72  }