PageRenderTime 23ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/PLANTILLA CLÁSICA 3/EDICION/scripts/as2lib/org/as2lib/env/log/logger/FludgeLogger.as

http://flash-web.googlecode.com/
ActionScript | 220 lines | 64 code | 19 blank | 137 comment | 7 complexity | a7a64c70fde122887740f95fd9d3a5f1 MD5 | raw file
  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. import org.as2lib.env.log.Logger;
  17. import org.as2lib.env.log.LogLevel;
  18. import org.as2lib.env.log.logger.AbstractLogger;
  19. /**
  20. * {@code FludgeLogger} delegates all log messages to the appropriate methods on
  21. * the {@code Fludge} class.
  22. *
  23. * <p>Using this class instead of the {@code Fludge} class in your application
  24. * directly enables you to switch between almost every available Logging API without
  25. * having to change the logging calls, but just the underlying configuration on
  26. * startup.
  27. *
  28. * @author Simon Wacker
  29. * @see org.as2lib.env.log.handler.FludgeHandler
  30. * @see <a href="http://www.osflash.org/doku.php?id=fludge">Fludge</a>
  31. */
  32. class org.as2lib.env.log.logger.FludgeLogger extends AbstractLogger implements Logger {
  33. /** Makes the static variables of the super-class accessible through this class. */
  34. private static var __proto__:Function = AbstractLogger;
  35. /** The set level. */
  36. private var level:LogLevel;
  37. /** The set level as number. */
  38. private var levelAsNumber:Number;
  39. /**
  40. * Constructs a new {@code FludgeLogger} instance.
  41. *
  42. * <p>The default log level is {@code ALL}. This means all messages regardless of
  43. * their level are logged.
  44. */
  45. public function FludgeLogger(Void) {
  46. level = ALL;
  47. levelAsNumber = level.toNumber();
  48. }
  49. /**
  50. * Sets the log level.
  51. *
  52. * <p>The log level determines which messages are logged and which are not.
  53. *
  54. * <p>A level of value {@code null} or {@code undefined} os interpreted as level
  55. * {@code ALL} which is also the default level.
  56. *
  57. * @param level the new log level
  58. */
  59. public function setLevel(level:LogLevel):Void {
  60. if (level) {
  61. this.level = level;
  62. levelAsNumber = level.toNumber();
  63. } else {
  64. this.level = ALL;
  65. levelAsNumber = level.toNumber();
  66. }
  67. }
  68. /**
  69. * Returns the set level.
  70. *
  71. * @return the set level
  72. */
  73. public function getLevel(Void):LogLevel {
  74. return level;
  75. }
  76. /**
  77. * Checks if this logger is enabled for debug level log messages.
  78. *
  79. * @return {@code true} if debug messages are logged
  80. * @see org.as2lib.env.log.level.AbstractLogLevel#DEBUG
  81. * @see #debug
  82. */
  83. public function isDebugEnabled(Void):Boolean {
  84. return (levelAsNumber >= debugLevelAsNumber);
  85. }
  86. /**
  87. * Checks if this logger is enabled for info level log messages.
  88. *
  89. * @return {@code true} if info messages are logged
  90. * @see org.as2lib.env.log.level.AbstractLogLevel#INFO
  91. * @see #info
  92. */
  93. public function isInfoEnabled(Void):Boolean {
  94. return (levelAsNumber >= infoLevelAsNumber);
  95. }
  96. /**
  97. * Checks if this logger is enabled for warning level log messages.
  98. *
  99. * @return {@code true} if warning messages are logged
  100. * @see org.as2lib.env.log.level.AbstractLogLevel#WARNING
  101. * @see #warning
  102. */
  103. public function isWarningEnabled(Void):Boolean {
  104. return (levelAsNumber >= warningLevelAsNumber);
  105. }
  106. /**
  107. * Checks if this logger is enabled for error level log messages.
  108. *
  109. * @return {@code true} if error messages are logged
  110. * @see org.as2lib.env.log.level.AbstractLogLevel#ERROR
  111. * @see #error
  112. */
  113. public function isErrorEnabled(Void):Boolean {
  114. return (levelAsNumber >= errorLevelAsNumber);
  115. }
  116. /**
  117. * Checks if this logger is enabled for fatal level log messages.
  118. *
  119. * @return {@code true} if fatal messages are logged
  120. * @see org.as2lib.env.log.level.AbstractLogLevel#FATAL
  121. * @see #fatal
  122. */
  123. public function isFatalEnabled(Void):Boolean {
  124. return (levelAsNumber >= fatalLevelAsNumber);
  125. }
  126. /**
  127. * Logs the passed-in {@code message} at debug level.
  128. *
  129. * <p>The {@code message} is only logged when the level is set to {@code DEBUG} or
  130. * a level above.
  131. *
  132. * <p>Because fludge does not support the debug level the default level info is
  133. * used.
  134. *
  135. * @param message the message object to log
  136. * @see #isDebugEnabled
  137. */
  138. public function debug(message):Void {
  139. if (isDebugEnabled()) {
  140. Fludge.trace(message.toString(), "debug");
  141. }
  142. }
  143. /**
  144. * Logs the passed-in {@code message} object at info level.
  145. *
  146. * <p>The {@code message} is only logged when the level is set to {@code INFO} or
  147. * a level above.
  148. *
  149. * @param message the message object to log
  150. * @see #isInfoEnabled
  151. */
  152. public function info(message):Void {
  153. if (isInfoEnabled()) {
  154. Fludge.trace(message.toString(), "info");
  155. }
  156. }
  157. /**
  158. * Logs the passed-in {@code message} object at warning level.
  159. *
  160. * <p>The {@code message} is only logged when the level is set to {@code WARNING}
  161. * or a level above.
  162. *
  163. * @param message the message object to log
  164. * @see #isWarningEnabled
  165. */
  166. public function warning(message):Void {
  167. if (isWarningEnabled()) {
  168. Fludge.trace(message.toString(), "warn");
  169. }
  170. }
  171. /**
  172. * Logs the passed-in {@code message} object at error level.
  173. *
  174. * <p>The {@code message} is only logged when the level is set to {@code ERROR} or
  175. * a level above.
  176. *
  177. * @param message the message object to log
  178. * @see #isErrorEnabled
  179. */
  180. public function error(message):Void {
  181. if (isErrorEnabled()) {
  182. Fludge.trace(message.toString(), "error");
  183. }
  184. }
  185. /**
  186. * Logs the passed-in {@code message} object at fatal level.
  187. *
  188. * <p>The {@code message} is only logged when the level is set to {@code FATAL} or
  189. * a level above.
  190. *
  191. * <p>The equivalent level for fatal in fludge is exception.
  192. *
  193. * @param message the message object to log
  194. * @see #isFatalEnabled
  195. */
  196. public function fatal(message):Void {
  197. if (isFatalEnabled()) {
  198. Fludge.trace(message.toString(), "exception");
  199. }
  200. }
  201. }