[ Index ]

PHP Cross Reference of phpBB-3.3.14-deutsch

title

Body

[close]

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

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


Generated: Mon Nov 25 19:05:08 2024 Cross-referenced by PHPXref 0.7.1