Source: tools/loggerDisabled.js

  1. define(
  2. /**
  3. * A "silent" replacement for the Logger factory.<br>
  4. * Has the same interface (functions etc.) as {@link mmir.Logging}.
  5. *
  6. * <p>
  7. *
  8. * This logging module allows to disable logging completely.
  9. *
  10. * <p>
  11. *
  12. * Which logging module is used, can be configured in core
  13. * module in {@link mmir}.
  14. *
  15. * <div class="box important">
  16. * <b>Note:</b> after configuration
  17. * of {@link mmir.debug} with <code>false</code>, this
  18. * logging module, i.e. the <code>DisabledLogging</code> factory with
  19. * its <code>DisabledLogger</code> implementation, will be available
  20. * via <code>mmir.Logging</code>(and <u><strong>not</strong></u> as
  21. * <em>mmir.DisabledLogger</em>).
  22. * </div>
  23. *
  24. * @class
  25. * @name DisabledLogging
  26. * @memberOf mmir
  27. * @static
  28. * @hideconstructor
  29. *
  30. * @see mmir.Logging
  31. *
  32. * @example
  33. *
  34. * var DisabledLogger = mmir.require('mmirf/loggerDisabled');
  35. * var logger = DisabledLogger.create('SomeClass');
  36. *
  37. * //same as above, if mmir.debug was set to false, before initialization:
  38. * var Logger = mmir.require('mmirf/logger');
  39. * var logger = Logging.create('SomeClass');
  40. */
  41. function(){
  42. /**
  43. * logging levels
  44. *
  45. * 0: verbose
  46. * 1: debug
  47. * 2: info
  48. * 3: warn
  49. * 4: error
  50. * 5: critical
  51. * 6: disabled
  52. */
  53. /**
  54. * NO-OP function
  55. * @private
  56. * @memberOf mmir.DisabledLogging#
  57. */
  58. function noop(){}
  59. /**
  60. * DENY function
  61. * @returns {Boolean} <code>false</code> (always)
  62. *
  63. * @private
  64. * @memberOf mmir.DisabledLogging#
  65. */
  66. function deny(){return false;}
  67. /**
  68. * Constructor-Method of Class DisabledLogger:
  69. * This logger implementation will never print logging output.
  70. *
  71. * Has the same interface (functions etc) as {@link mmir.tools.Logger} of the {@link mmir.Logging} factory,
  72. * but <em>isXXX</em> functions will always return <code>false</code>
  73. * and the logging-functions will never do anything (i.e. these are
  74. * <em>no-op</em> functions).
  75. *
  76. * @constructor
  77. * @name DisabledLogger
  78. * @memberOf mmir.tools
  79. */
  80. function Logger(){}
  81. Logger.prototype =
  82. /** @lends mmir.tools.DisabledLogger# */
  83. {//public instance members (basically all NO-OPs or DENYs)
  84. /**
  85. * @public
  86. * @function
  87. */
  88. getLevel : function(){
  89. //always return "disabled" level:
  90. return 6;
  91. },
  92. /**
  93. * @public
  94. * @function
  95. */
  96. setLevel : noop,
  97. /**
  98. * @public
  99. * @function
  100. */
  101. log: noop,
  102. /**
  103. * @public
  104. * @function
  105. */
  106. verbose: noop,
  107. /**
  108. * @public
  109. * @function
  110. */
  111. debug: noop,
  112. /**
  113. * @public
  114. * @function
  115. */
  116. info: noop,
  117. /**
  118. * @public
  119. * @function
  120. */
  121. warn: noop,
  122. /**
  123. * @public
  124. * @function
  125. */
  126. error: noop,
  127. /**
  128. * @public
  129. * @function
  130. */
  131. critical: noop,
  132. /**
  133. * @public
  134. * @function
  135. */
  136. isVerbose: deny,
  137. /**
  138. * @public
  139. * @function
  140. */
  141. isDebug: deny,
  142. /**
  143. * @public
  144. * @function
  145. */
  146. isInfo: deny,
  147. /**
  148. * @public
  149. * @function
  150. */
  151. isWarn: deny,
  152. /**
  153. * @public
  154. * @function
  155. */
  156. isError: deny,
  157. /**
  158. * @public
  159. * @function
  160. */
  161. isCritical: deny,
  162. /**
  163. * @public
  164. * @function
  165. */
  166. isDisabled: deny,
  167. /**
  168. * @public
  169. * @function
  170. */
  171. v: noop,
  172. /**
  173. * @public
  174. * @function
  175. */
  176. d: noop,
  177. /**
  178. * @public
  179. * @function
  180. */
  181. i: noop,
  182. /**
  183. * @public
  184. * @function
  185. */
  186. w: noop,
  187. /**
  188. * @public
  189. * @function
  190. */
  191. e: noop,
  192. /**
  193. * @public
  194. * @function
  195. */
  196. c: noop,
  197. /**
  198. * @public
  199. * @function
  200. */
  201. isv: deny,
  202. /**
  203. * @public
  204. * @function
  205. */
  206. isd: deny,
  207. /**
  208. * @public
  209. * @function
  210. */
  211. isi: deny,
  212. /**
  213. * @public
  214. * @function
  215. */
  216. isw: deny,
  217. /**
  218. * @public
  219. * @function
  220. */
  221. ise: deny,
  222. /**
  223. * @public
  224. * @function
  225. */
  226. isc: deny
  227. };
  228. /**
  229. * @private
  230. * @memberOf mmir.DisabledLogging#
  231. */
  232. var _defaultLogger = new Logger();
  233. return /** @lends mmir.DisabledLogging# */ {//public API
  234. /**
  235. * Will always return the default logger for this logging module
  236. * @returns {mmir.tools.DisabledLogger}
  237. *
  238. * @public
  239. * @memberOf mmir.DisabledLogging.prototype
  240. */
  241. create: function(){
  242. return _defaultLogger;
  243. },
  244. /**
  245. * @public
  246. */
  247. get: function(){
  248. return _defaultLogger;
  249. },
  250. /**
  251. * @public
  252. * @function
  253. */
  254. setDefaultLogLevel: noop,
  255. /**
  256. * @public
  257. */
  258. getDefaultLogLevel: function(){
  259. return 6;
  260. },
  261. /**
  262. * @public
  263. * @function
  264. */
  265. log: noop,
  266. /**
  267. * @public
  268. * @function
  269. */
  270. verbose: noop,
  271. /**
  272. * @public
  273. * @function
  274. */
  275. debug: noop,
  276. /**
  277. * @public
  278. * @function
  279. */
  280. info: noop,
  281. /**
  282. * @public
  283. * @function
  284. */
  285. warn: noop,
  286. /**
  287. * @public
  288. * @function
  289. */
  290. error: noop,
  291. // isDebug: deny,
  292. // isInfo: deny,
  293. // isWarn: deny,
  294. // isError: deny
  295. /**
  296. * Special property for identifying the disabled logger-factory
  297. * @public
  298. */
  299. isDisabledLogger: true
  300. };
  301. });