[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/vendor/s9e/text-formatter/src/Parser/ -> Logger.js (source)

   1  /**
   2  * @constructor
   3  */
   4  function Logger()
   5  {
   6  }
   7  
   8  /**
   9  * @type {string} Name of the attribute being processed
  10  */
  11  Logger.prototype.attrName;
  12  
  13  /**
  14  * @type {!Object.<string,!Array>} 2D array of [<log type> => [<callbacks>]]
  15  */
  16  Logger.prototype.callbacks = {};
  17  
  18  /**
  19  * @type {!Array.<!Array>} Log entries in the form [[<type>,<msg>,<context>]]
  20  */
  21  Logger.prototype.logs = [];
  22  
  23  /**
  24  * @type {Tag} Tag being processed
  25  */
  26  Logger.prototype.tag;
  27  
  28  /**
  29  * Add a log entry
  30  *
  31  * @param  {!string}  type    Log type
  32  * @param  {!string}  msg     Log message
  33  * @param  {!Object=} context Log context
  34  */
  35  Logger.prototype.add = function(type, msg, context)
  36  {
  37      context = context || {};
  38  
  39      if (!('attrName' in context) && this.attrName)
  40      {
  41          context['attrName'] = this.attrName;
  42      }
  43  
  44      if (!('tag' in context) && this.tag)
  45      {
  46          context['tag'] = this.tag;
  47      }
  48  
  49      // Execute callbacks
  50      if (this.callbacks[type])
  51      {
  52          this.callbacks[type].forEach(function(callback)
  53          {
  54              callback(msg, context);
  55          });
  56      }
  57  
  58      this.logs.push([type, msg, context]);
  59  }
  60  
  61  /**
  62  * Clear the log
  63  */
  64  Logger.prototype.clear = function()
  65  {
  66      this.logs = [];
  67      this.unsetAttribute();
  68      this.unsetTag();
  69  }
  70  
  71  /**
  72  * Return the logs
  73  *
  74  * @return {!Object}
  75  */
  76  Logger.prototype['getLogs'] = function()
  77  {
  78      return this.logs;
  79  }
  80  
  81  /**
  82  * Attach a callback to be executed when a message of given type is logged
  83  *
  84  * @param {!string}   type     Log type
  85  * @param {!Function} callback Callback
  86  */
  87  Logger.prototype['on'] = function(type, callback)
  88  {
  89      this.callbacks[type].push(callback);
  90  }
  91  
  92  /**
  93  * Record the name of the attribute being processed
  94  *
  95  * @param  {!string} attrName
  96  */
  97  Logger.prototype.setAttribute = function(attrName)
  98  {
  99      this.attrName = attrName;
 100  }
 101  
 102  /**
 103  * Record the tag being processed
 104  *
 105  * @param  {!Tag} tag
 106  */
 107  Logger.prototype.setTag = function(tag)
 108  {
 109      this.tag = tag;
 110  }
 111  
 112  /**
 113  * Unset the name of the attribute being processed
 114  */
 115  Logger.prototype.unsetAttribute = function()
 116  {
 117      delete this.attrName;
 118  }
 119  
 120  /**
 121  * Unset the tag being processed
 122  */
 123  Logger.prototype.unsetTag = function()
 124  {
 125      delete this.tag;
 126  }
 127  
 128  //==========================================================================
 129  // Log levels
 130  //==========================================================================
 131  
 132  /**
 133  * Add a "debug" type log entry
 134  *
 135  * @param  {!string}  msg     Log message
 136  * @param  {!Object=} context Log context
 137  */
 138  Logger.prototype.debug = function(msg, context)
 139  {
 140      this.add('debug', msg, context);
 141  }
 142  
 143  /**
 144  * Add an "err" type log entry
 145  *
 146  * @param  {!string}  msg     Log message
 147  * @param  {!Object=} context Log context
 148  */
 149  Logger.prototype.err = function(msg, context)
 150  {
 151      this.add('err', msg, context);
 152  }
 153  
 154  /**
 155  * Add an "info" type log entry
 156  *
 157  * @param  {!string}  msg     Log message
 158  * @param  {!Object=} context Log context
 159  */
 160  Logger.prototype.info = function(msg, context)
 161  {
 162      this.add('info', msg, context);
 163  }
 164  
 165  /**
 166  * Add a "warn" type log entry
 167  *
 168  * @param  {!string}  msg     Log message
 169  * @param  {!Object=} context Log context
 170  */
 171  Logger.prototype.warn = function(msg, context)
 172  {
 173      this.add('warn', msg, context);
 174  }


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1