      1 var define = require("../../define.js").define, base = require("../../base"), Level = require("../level");
      2
      3 /**
      4  * @class Base class for all appenders
      5  *
      6  * @name Appender
      7  * @memberOf comb.logging.appenders
      8  *
      9  * @param {Object} [options] options to assign to this Appender
     10  * @param {String} [options.name="appender"] the name of this Appender. If you want two of the same type of appender
     11  *                                           on a logger it must have a different name.
     12  * @param {String} [options.pattern="[{[yyyy-MM-ddTHH:mm:ss:SSS (z)]timeStamp}] {[- 5]levelName} {[-20]name} - {message}"]
     13  *  <p>Available Options for formatting see {@link comb.string.format} for formatting options</p>
     14  *  <ul>
     15  *      <li>timeStamp - the timestamp of the event being logged</li>
     16  *      <li>level - the {@link comb.logging.Level} of the event</li>
     17  *      <li>levelName - the name of the level being logged</li>
     18  *      <li>name - the name of the logger logging the event</li>
     19  *      <li>message - the message being logged</li>
     20  * </ul>
     21  * @param {comb.logging.Level|String} [options.level=comb.logging.Level.INFO] the logging level of this appender
     22  *      <p><b>Note:</b> the level can be different from the logger in the case that you want a particular logger
     23  *      to only log particular event of a level. For example an appender that only logs errors. BEWARE that if the
     24  *      appenders level is lower than the logger is will not recieve any messages.</p>
     25  *
     26  * @property {String} name the name of this Appender.
     27  * @property {String} pattern the pattern for this Appender.
     28  * @property {comb.logging.Level} level the level of this Appender.
     29  */
     30 var Appender = (exports = module.exports = define(null, {
     31 			instance : {
     32 				/**@lends comb.logging.appenders.Appender.prototype*/
     33
     34 				constructor : function(options) {
     35 					options = options || {};
     36 					this.name = options.name || "appender";
     37 					this.pattern = options.pattern || "[{[yyyy-MM-ddTHH:mm:ss:SSS (z)]timeStamp}] {[- 5]levelName} {[-20]name} - {message}";
     38 					var level = options.level;
     39 					if(options.level && (level = Level.toLevel(level))){
     40 						this.__level = level;
     41 					}else{
     42 						this.__level = Level.INFO;
     43 					}
     44 				},
     45
     46 				/**
     47 				 * Appends a message to a log.
     48 				 * <b>This method is abstract and must be implemented in subclasses</b>
     49 				 * @param {Object} event the logging event to log.
     50 				 * @param {Date} event.timeStamp the timeStamp of the event.
     51 				 * @param {comb.logging.Level} level the level of the event.
     52 				 * @param {String} name the name of the logger the event was emitted from.
     53 				 * @param {String} message the message that is being logged.
     54 				 *
     55 				 */
     56 				append : function(event) {
     57 					throw new Error("abstract method");
     58 				},
     59
     60 				_canAppend : function(event) {
     61 					return event.level.isGreaterOrEqualToo(this.__level);
     62 				},
     63
     64 				/**@ignore*/
     65 				setters : {
     66 					/**@ignore*/
     67
     68 					level : function(level) {
     69 						if (level && level instanceof Level) {
     70 							this.__level = level;
     71 						} else {
     72 							//try to get the level
     73 							level = Level.toLevel(level);
     74 							if (level) {
     75 								this.__level = level;
     76 							}
     77 						}
     78 					},
     79
     80 					pattern : function(patt){
     81 						if(base.isString(patt)){
     82 							this.__pattern = patt;
     83 						}
     84 					},
     85
     86 					name : function(name){
     87 						if(base.isString(name)){
     88 							this.__name = name;
     89 						}
     90 					}
     91 				},
     92
     93 				/**@ignore*/
     94 				getters : {
     95 					/**@ignore*/
     96
     97 					level : function() {
     98 						return this.__level;
     99 					},
    100
    101 					name : function() {
    102 						return this.__name;
    103 					},
    104
    105 					pattern : function(){
    106 						return this.__pattern;
    107 					}
    108 				}
    109 			}
    110
    111 		}));