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.core.BasicClass; 18 import org.as2lib.util.Stringifier; 19 import org.as2lib.env.log.LogMessage; 20 21 /** 22 * {@code AbstractLogHandler} provides methods that are commonly needed by 23 * {@link LogHandler} implementations. 24 * 25 * @author Simon Wacker 26 */ 27 class org.as2lib.env.log.handler.AbstractLogHandler extends BasicClass { 28 29 /** The log message stringifier. */ 30 private var messageStringifier:Stringifier; 31 32 /** 33 * Constructs a new {@code AbstractLogHandler} instance. 34 * 35 * @param messageStringifier (optional) the log message stringifier to use 36 */ 37 public function AbstractLogHandler(messageStringifier:Stringifier) { 38 this.messageStringifier = messageStringifier; 39 } 40 41 /** 42 * Converts the passed-in {@code message} into a string. 43 * 44 * <p>If the message stringifier set on construction is not {@code null} nor 45 * {@code undefined}, it will be used for conversion. Otherwise the 46 * {@code toString} method of the passed-in {@code message} will be used. 47 * 48 * @param message the log message to convert 49 * @return the string representation of the passed-in {@code message} 50 */ 51 private function convertMessage(message:LogMessage):String { 52 if (this.messageStringifier) { 53 return this.messageStringifier.execute(message); 54 } 55 return message.toString(); 56 } 57 58 }