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.env.log.Logger; 19 20 import LuminicBox.Log.Level; 21 import LuminicBox.Log.IPublisher; 22 23 /** 24 * {@code LuminicBoxLogger} acts as a wrapper for a {@code Logger} instance of the 25 * LuminicBox Logging API. 26 * 27 * <p>Configure the LuminicBox Logging API as normally and just use this class in 28 * your application to log messages or objects. This enables you to switch between 29 * almost every available Logging API without having to change the logs in your 30 * application but just the underlying configuration on startup. 31 * 32 * <p>All functionalities that the LuminicBox Logging API offers are delegated to 33 * it. Other functionalities are performed by this class directly. 34 * 35 * @author Simon Wacker 36 * @author Christoph Atteneder 37 * 38 * @see org.as2lib.env.log.handler.LuminicBoxHandler 39 * @see <a href="http://www.luminicbox.com/dev/flash/log">LuminicBox Logging API</a> 40 */ 41 class org.as2lib.env.log.logger.LuminicBoxLogger extends BasicClass implements Logger { 42 43 /** The Logger instance of LuminicBox every task is delegated to. */ 44 private var logger:LuminicBox.Log.Logger; 45 46 /** The set level as number. */ 47 private var levelAsNumber:Number; 48 49 /** Debug level as number. */ 50 private var debugLevelAsNumber:Number; 51 52 /** Info level as number. */ 53 private var infoLevelAsNumber:Number; 54 55 /** Warning level as number. */ 56 private var warningLevelAsNumber:Number; 57 58 /** Error level as number. */ 59 private var errorLevelAsNumber:Number; 60 61 /** Fatal level as number. */ 62 private var fatalLevelAsNumber:Number; 63 64 /** 65 * Constructs a new {@code LuminicBoxLogger} instance. 66 * 67 * @param name (optional) the name of this logger 68 */ 69 public function LuminicBoxLogger(name:String) { 70 this.logger = new LuminicBox.Log.Logger(name); 71 this.levelAsNumber = getLevel().getValue(); 72 this.debugLevelAsNumber = Level.DEBUG.getValue(); 73 this.infoLevelAsNumber = Level.INFO.getValue(); 74 this.warningLevelAsNumber = Level.WARN.getValue(); 75 this.errorLevelAsNumber = Level.ERROR.getValue(); 76 this.fatalLevelAsNumber = Level.FATAL.getValue(); 77 } 78 79 /** 80 * Returns the name of this logger. 81 * 82 * @return the name of this logger 83 */ 84 public function getName(Void):String { 85 return this.logger.getId(); 86 } 87 88 /** 89 * Sets the new level. 90 * 91 * <p>The level determines which messages are logged and which are not. 92 * 93 * @param newLevel the new level 94 */ 95 public function setLevel(newLevel:Level):Void { 96 this.logger.setLevel(newLevel); 97 this.levelAsNumber = newLevel.getValue(); 98 } 99 100 /** 101 * Returns the set or default level. 102 * 103 * @return the set or default level 104 */ 105 public function getLevel(Void):Level { 106 return this.logger.getLevel(); 107 } 108 109 /** 110 * Adds the {@code publisher} to the wrapped LuminicBox {@code Logger}. 111 * 112 * @param publisher the publisher to add 113 */ 114 public function addPublisher(publisher:IPublisher):Void { 115 logger.addPublisher(publisher); 116 } 117 118 /** 119 * Removes the {@code publisher} from the wrapped LuminicBox {@code Logger}. 120 * 121 * @param publisher the publisher to remove 122 */ 123 public function removePublisher(publisher:IPublisher):Void { 124 logger.removePublisher(publisher); 125 } 126 127 /** 128 * Returns the added publishers of type {@code IPublisher}. 129 * 130 * @return the added publishers 131 * @see #addPublisher 132 */ 133 public function getPublishers(Void):Object { 134 return logger.getPublishers(); 135 } 136 137 /** 138 * Checks if this logger is enabled for debug level log messages. 139 * 140 * @return {@code true} if debug messages are logged 141 * @see #debug 142 */ 143 public function isDebugEnabled(Void):Boolean { 144 return (levelAsNumber <= debugLevelAsNumber); 145 } 146 147 /** 148 * Checks if this logger is enabled for info level log messages. 149 * 150 * @return {@code true} if info messages are logged 151 * @see #info 152 */ 153 public function isInfoEnabled(Void):Boolean { 154 return (levelAsNumber <= infoLevelAsNumber); 155 } 156 157 /** 158 * Checks if this logger is enabled for warning level log messages. 159 * 160 * @return {@code true} if warning messages are logged 161 * @see #warning 162 */ 163 public function isWarningEnabled(Void):Boolean { 164 return (levelAsNumber <= warningLevelAsNumber); 165 } 166 167 /** 168 * Checks if this logger is enabled for error level log messages. 169 * 170 * @return {@code true} if error messages are logged 171 * @see #error 172 */ 173 public function isErrorEnabled(Void):Boolean { 174 return (levelAsNumber <= errorLevelAsNumber); 175 } 176 177 /** 178 * Checks if this logger is enabled for fatal level log messages. 179 * 180 * @return {@code true} if fatal messages are logged 181 * @see #fatal 182 */ 183 public function isFatalEnabled(Void):Boolean { 184 return (levelAsNumber <= fatalLevelAsNumber); 185 } 186 187 /** 188 * Logs the passed-in {@code message} to LuminicBox {@code Logger} at debug level. 189 * 190 * @param message the message object to log 191 * @see #isDebugEnabled 192 */ 193 public function debug(message):Void { 194 logger.debug(message); 195 } 196 197 /** 198 * Logs the passed-in {@code message} to LuminicBox {@code Logger} at info level. 199 * 200 * @param message the message object to log 201 * @see #isInfoEnabled 202 */ 203 public function info(message):Void { 204 logger.info(message); 205 } 206 207 /** 208 * Logs the passed-in {@code message} to LuminicBox {@code Logger} at warning 209 * level. 210 * 211 * @param message the message object to log 212 * @see #isWarningEnabled 213 */ 214 public function warning(message):Void { 215 logger.warn(message); 216 } 217 218 /** 219 * Logs the passed-in {@code message} to LuminicBox {@code Logger} at error level. 220 * 221 * @param message the message object to log 222 * @see #isErrorEnabled 223 */ 224 public function error(message):Void { 225 logger.error(message); 226 } 227 228 /** 229 * Logs the passed-in {@code message} to LuminicBox {@code Logger} at fatal level. 230 * 231 * @param message the message object to log 232 * @see #isFatalEnabled 233 */ 234 public function fatal(message):Void { 235 logger.fatal(message); 236 } 237 238 }