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.Logger; 18 import org.as2lib.env.log.LogLevel; 19 import org.as2lib.env.log.logger.AbstractLogger; 20 21 /** 22 * {@code FlashoutLogger} delegates all log messages to the appropriate methods on 23 * the {@code Flashout} class. 24 * 25 * <p>Using this class instead of the {@code Flashout} class in your application 26 * directly enables you to switch between almost every available Logging API without 27 * having to change the logging calls, but just the underlying configuration on 28 * startup. 29 * 30 * <p>Note that if you are working with the Flashout 0.2.* you have to specify 31 * Flashout's custom trace method as trace replacement when compiling your classes 32 * with MTASC. 33 * 34 * @author Simon Wacker 35 * @see org.as2lib.env.log.handler.FlashoutHandler 36 * @see <a href="http://www.potapenko.com/flashout">Flashout</a> 37 */ 38 class org.as2lib.env.log.logger.FlashoutLogger extends AbstractLogger implements Logger { 39 40 /** Makes the static variables of the super-class accessible through this class. */ 41 private static var __proto__:Function = AbstractLogger; 42 43 /** The set level. */ 44 private var level:LogLevel; 45 46 /** The set level as number. */ 47 private var levelAsNumber:Number; 48 49 /** 50 * Constructs a new {@code FlashoutLogger} instance. 51 * 52 * <p>The default log level is {@code ALL}. This means all messages regardless of 53 * their level are logged. 54 */ 55 public function FlashoutLogger(Void) { 56 level = ALL; 57 levelAsNumber = level.toNumber(); 58 } 59 60 /** 61 * Sets the log level. 62 * 63 * <p>The log level determines which messages are logged and which are not. 64 * 65 * <p>A level of value {@code null} or {@code undefined} os interpreted as level 66 * {@code ALL} which is also the default level. 67 * 68 * @param level the new log level 69 */ 70 public function setLevel(level:LogLevel):Void { 71 if (level) { 72 this.level = level; 73 levelAsNumber = level.toNumber(); 74 } else { 75 this.level = ALL; 76 levelAsNumber = level.toNumber(); 77 } 78 } 79 80 /** 81 * Returns the set level. 82 * 83 * @return the set level 84 */ 85 public function getLevel(Void):LogLevel { 86 return level; 87 } 88 89 /** 90 * Checks if this logger is enabled for debug level log messages. 91 * 92 * @return {@code true} if debug messages are logged 93 * @see org.as2lib.env.log.level.AbstractLogLevel#DEBUG 94 * @see #debug 95 */ 96 public function isDebugEnabled(Void):Boolean { 97 return (levelAsNumber >= debugLevelAsNumber); 98 } 99 100 /** 101 * Checks if this logger is enabled for info level log messages. 102 * 103 * @return {@code true} if info messages are logged 104 * @see org.as2lib.env.log.level.AbstractLogLevel#INFO 105 * @see #info 106 */ 107 public function isInfoEnabled(Void):Boolean { 108 return (levelAsNumber >= infoLevelAsNumber); 109 } 110 111 /** 112 * Checks if this logger is enabled for warning level log messages. 113 * 114 * @return {@code true} if warning messages are logged 115 * @see org.as2lib.env.log.level.AbstractLogLevel#WARNING 116 * @see #warning 117 */ 118 public function isWarningEnabled(Void):Boolean { 119 return (levelAsNumber >= warningLevelAsNumber); 120 } 121 122 /** 123 * Checks if this logger is enabled for error level log messages. 124 * 125 * @return {@code true} if error messages are logged 126 * @see org.as2lib.env.log.level.AbstractLogLevel#ERROR 127 * @see #error 128 */ 129 public function isErrorEnabled(Void):Boolean { 130 return (levelAsNumber >= errorLevelAsNumber); 131 } 132 133 /** 134 * Checks if this logger is enabled for fatal level log messages. 135 * 136 * @return {@code true} if fatal messages are logged 137 * @see org.as2lib.env.log.level.AbstractLogLevel#FATAL 138 * @see #fatal 139 */ 140 public function isFatalEnabled(Void):Boolean { 141 return (levelAsNumber >= fatalLevelAsNumber); 142 } 143 144 /** 145 * Logs the passed-in {@code message} at debug level. 146 * 147 * <p>The {@code message} is only logged when the level is set to {@code DEBUG} or 148 * a level above. 149 * 150 * <p>The {@code message} is logged using the {@code Flashout.debug} method. 151 * 152 * @param message the message object to log 153 * @see #isDebugEnabled 154 */ 155 public function debug(message):Void { 156 if (isDebugEnabled()) { 157 Flashout.debug(message); 158 } 159 } 160 161 /** 162 * Logs the passed-in {@code message} object at info level. 163 * 164 * <p>The {@code message} is only logged when the level is set to {@code INFO} or 165 * a level above. 166 * 167 * <p>The {@code message} is logged using the {@code Flashout.info} method. 168 * 169 * @param message the message object to log 170 * @see #isInfoEnabled 171 */ 172 public function info(message):Void { 173 if (isInfoEnabled()) { 174 Flashout.info(message); 175 } 176 } 177 178 /** 179 * Logs the passed-in {@code message} object at warning level. 180 * 181 * <p>The {@code message} is only logged when the level is set to {@code WARNING} 182 * or a level above. 183 * 184 * <p>The {@code message} is logged using the {@code Flashout.warning} method. 185 * 186 * @param message the message object to log 187 * @see #isWarningEnabled 188 */ 189 public function warning(message):Void { 190 if (isWarningEnabled()) { 191 Flashout.warning(message); 192 } 193 } 194 195 /** 196 * Logs the passed-in {@code message} object at error level. 197 * 198 * <p>The {@code message} is only logged when the level is set to {@code ERROR} or 199 * a level above. 200 * 201 * <p>The {@code message} is logged using the {@code Flashout.error} method. 202 * 203 * @param message the message object to log 204 * @see #isErrorEnabled 205 */ 206 public function error(message):Void { 207 if (isErrorEnabled()) { 208 Flashout.error(message); 209 } 210 } 211 212 /** 213 * Logs the passed-in {@code message} object at fatal level. 214 * 215 * <p>The {@code message} is only logged when the level is set to {@code FATAL} or 216 * a level above. 217 * 218 * <p>The {@code message} is logged using the {@code Flashout.error} method. 219 * 220 * @param message the message object to log 221 * @see #isFatalEnabled 222 */ 223 public function fatal(message):Void { 224 if (isFatalEnabled()) { 225 // old Flashout did not provide fatal level 226 // wanted support to be compatible with both versions 227 if (Flashout["fatal"]) { 228 Flashout["fatal"](message); 229 } else { 230 Flashout.error(message); 231 } 232 } 233 } 234 235 }