1 /*
  2  * 	Copyright (C) 2012-2015 DFKI GmbH
  3  * 	Deutsches Forschungszentrum fuer Kuenstliche Intelligenz
  4  * 	German Research Center for Artificial Intelligence
  5  * 	http://www.dfki.de
  6  * 
  7  * 	Permission is hereby granted, free of charge, to any person obtaining a 
  8  * 	copy of this software and associated documentation files (the 
  9  * 	"Software"), to deal in the Software without restriction, including 
 10  * 	without limitation the rights to use, copy, modify, merge, publish, 
 11  * 	distribute, sublicense, and/or sell copies of the Software, and to 
 12  * 	permit persons to whom the Software is furnished to do so, subject to 
 13  * 	the following conditions:
 14  * 
 15  * 	The above copyright notice and this permission notice shall be included 
 16  * 	in all copies or substantial portions of the Software.
 17  * 
 18  * 	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 
 19  * 	OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
 20  * 	MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
 21  * 	IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 
 22  * 	CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 
 23  * 	TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 
 24  * 	SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 25  */
 26 
 27 
 28 
 29 define( 
 30 /**
 31  * A "silent" replacement for the Logger factory.<br>
 32  * Has the same interface (functions etc.) as {@link mmir.Logging}.
 33  * 
 34  * <p>
 35  * 
 36  * This logging module allows to disable logging completely.
 37  * 
 38  * <p>
 39  * 
 40  * Which logging module is used, can be configured in core
 41  * module in {@link mmir}.
 42  * 
 43  * <div class="box important">
 44  * 	<b>Note:</b> after configuration
 45  * 	of {@link mmir.debug} with <code>false</code>, this
 46  * 	logging module, i.e. the <code>DisabledLogging</code> factory with
 47  * 	its <code>DisabledLogger</code> implementation, will be available 
 48  * 	via <code>mmir.Logging</code>(and <u><strong>not</strong></u> as 
 49  * 	<em>mmir.DisabledLogger</em>).
 50  * </div>
 51  * 
 52  * @class
 53  * @name DisabledLogging
 54  * @memberOf mmir
 55  * @static
 56  * 
 57  * @see mmir.Logging
 58  * 
 59  * @example mmir.Logging.create('SomeClass')
 60  */
 61 function(){
 62 
 63 /**
 64  * logging levels
 65  * 
 66  * 0: verbose
 67  * 1: debug
 68  * 2: info
 69  * 3: warn
 70  * 4: error
 71  * 5: critical
 72  * 6: disabled
 73  */
 74 
 75 
 76 /** 
 77  * NO-OP function
 78  * @private
 79  * @memberOf DisabledLogging#
 80  */
 81 function noop(){}
 82 /** 
 83  * DENY function
 84  * @returns {Boolean} <code>false</code> (always)
 85  * 
 86  * @private
 87  * @memberOf DisabledLogging#
 88  */
 89 function deny(){return false;}
 90 
 91 /**
 92  * Constructor-Method of Class DisabledLogger:
 93  * This logger implementation will never print logging output.
 94  * 
 95  * Has the same interface (functions etc) as {@link Logger} of the {@link mmir.Logging} factory,
 96  * but <em>isXXX</em> functions will always return <code>false</code>
 97  * and the logging-functions will never do anything (i.e. these are
 98  * <em>no-op</em> functions).
 99  * 
100  * @constructor
101  * @name DisabledLogger
102  */
103 function Logger(){}
104 
105 
106 Logger.prototype =
107 /** @lends DisabledLogger# */
108 {//public instance members (basically all NO-OPs or DENYs)
109 	
110 	/** 
111 	 * @public
112 	 * @function
113 	 */
114     getLevel : function(){
115     	//always return "disabled" level:
116     	return 6;
117     },
118     /** 
119 	 * @public
120 	 * @function
121 	 */
122     setLevel : noop,
123     /** 
124 	 * @public
125 	 * @function
126 	 */
127     log: noop,
128     /** 
129 	 * @public
130 	 * @function
131 	 */
132     verbose: noop,
133     /** 
134 	 * @public
135 	 * @function
136 	 */
137     debug: noop,
138     /** 
139 	 * @public
140 	 * @function
141 	 */
142     info: noop,
143     /** 
144 	 * @public
145 	 * @function
146 	 */
147     warn: noop,
148     /** 
149 	 * @public
150 	 * @function
151 	 */
152     error: noop,
153     /** 
154 	 * @public
155 	 * @function
156 	 */
157     critical: noop,
158     /** 
159 	 * @public
160 	 * @function
161 	 */
162     isVerbose: deny,
163     /** 
164 	 * @public
165 	 * @function
166 	 */
167     isDebug: deny,
168     /** 
169 	 * @public
170 	 * @function
171 	 */
172     isInfo: deny,
173     /** 
174 	 * @public
175 	 * @function
176 	 */
177     isWarn: deny,
178     /** 
179 	 * @public
180 	 * @function
181 	 */
182     isError: deny,
183     /** 
184 	 * @public
185 	 * @function
186 	 */
187     isCritical: deny,
188     /** 
189 	 * @public
190 	 * @function
191 	 */
192     isDisabled: deny,
193     /** 
194 	 * @public
195 	 * @function
196 	 */
197     v: noop,
198     /** 
199 	 * @public
200 	 * @function
201 	 */
202     d: noop,
203     /** 
204 	 * @public
205 	 * @function
206 	 */
207     i: noop,
208     /** 
209 	 * @public
210 	 * @function
211 	 */
212     w: noop,
213     /** 
214 	 * @public
215 	 * @function
216 	 */
217     e: noop,
218     /** 
219 	 * @public
220 	 * @function
221 	 */
222     c: noop,
223     /** 
224 	 * @public
225 	 * @function
226 	 */
227     isv: deny,
228     /** 
229 	 * @public
230 	 * @function
231 	 */
232     isd: deny,
233     /** 
234 	 * @public
235 	 * @function
236 	 */
237     isi: deny,
238     /** 
239 	 * @public
240 	 * @function
241 	 */
242     isw: deny,
243     /** 
244 	 * @public
245 	 * @function
246 	 */
247     ise: deny,
248     /** 
249 	 * @public
250 	 * @function
251 	 */
252     isc: deny
253 };
254 
255 /**
256  * @private
257  * @memberOf mmir.DisabledLogging#
258  */
259 var _defaultLogger = new Logger();
260 
261 return /** @lends mmir.DisabledLogging# */ {//public API
262 	
263 	/**
264 	 * Will always return the default logger for this logging module
265 	 * @returns {DisabledLogger}
266 	 * 
267 	 * @public
268 	 * @memberOf mmir.DisabledLogging.prototype
269 	 */
270     create: function(){
271         return _defaultLogger;
272     },
273     /** 
274 	 * @public
275 	 */
276     get: function(){
277         return _defaultLogger;
278     },
279     /** 
280 	 * @public
281 	 * @function
282 	 */
283     setDefaultLogLevel: noop,
284     /** 
285 	 * @public
286 	 */
287     getDefaultLogLevel: function(){
288     	return 6;
289     },
290     /** 
291 	 * @public
292 	 * @function
293 	 */
294     log: noop,
295     /** 
296 	 * @public
297 	 * @function
298 	 */
299     verbose: noop,
300     /** 
301 	 * @public
302 	 * @function
303 	 */
304     debug: noop,
305     /** 
306 	 * @public
307 	 * @function
308 	 */
309     info: noop,
310     /** 
311 	 * @public
312 	 * @function
313 	 */
314     warn: noop,
315     /** 
316 	 * @public
317 	 * @function
318 	 */
319     error: noop,
320 //    isDebug: deny,
321 //    isInfo: deny,
322 //    isWarn: deny,
323 //    isError: deny
324     /** 
325      * Special property for identifying the disabled logger-factory
326 	 * @public
327 	 */
328     isDisabledLogger: true
329 };
330     
331 });
332