Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

Logger.js

Zuletzt modifiziert: 09.10.2024, 12:57 - Dateigröße: 2.95 KiB


 001  /**
 002  * @constructor
 003  */
 004  function Logger()
 005  {
 006  }
 007   
 008  /**
 009  * @type {string} Name of the attribute being processed
 010  */
 011  Logger.prototype.attrName;
 012   
 013  /**
 014  * @type {!Object.<string,!Array>} 2D array of [<log type> => [<callbacks>]]
 015  */
 016  Logger.prototype.callbacks = {};
 017   
 018  /**
 019  * @type {!Array.<!Array>} Log entries in the form [[<type>,<msg>,<context>]]
 020  */
 021  Logger.prototype.logs = [];
 022   
 023  /**
 024  * @type {Tag} Tag being processed
 025  */
 026  Logger.prototype.tag;
 027   
 028  /**
 029  * Add a log entry
 030  *
 031  * @param  {!string}  type    Log type
 032  * @param  {!string}  msg     Log message
 033  * @param  {!Object=} context Log context
 034  */
 035  Logger.prototype.add = function(type, msg, context)
 036  {
 037      context = context || {};
 038   
 039      if (!('attrName' in context) && this.attrName)
 040      {
 041          context['attrName'] = this.attrName;
 042      }
 043   
 044      if (!('tag' in context) && this.tag)
 045      {
 046          context['tag'] = this.tag;
 047      }
 048   
 049      // Execute callbacks
 050      if (this.callbacks[type])
 051      {
 052          this.callbacks[type].forEach(function(callback)
 053          {
 054              callback(msg, context);
 055          });
 056      }
 057   
 058      this.logs.push([type, msg, context]);
 059  }
 060   
 061  /**
 062  * Clear the log
 063  */
 064  Logger.prototype.clear = function()
 065  {
 066      this.logs = [];
 067      this.unsetAttribute();
 068      this.unsetTag();
 069  }
 070   
 071  /**
 072  * Return the logs
 073  *
 074  * @return {!Object}
 075  */
 076  Logger.prototype['get'] = function()
 077  {
 078      return this.logs;
 079  }
 080   
 081  /**
 082  * Attach a callback to be executed when a message of given type is logged
 083  *
 084  * @param {!string}   type     Log type
 085  * @param {!Function} callback Callback
 086  */
 087  Logger.prototype['on'] = function(type, callback)
 088  {
 089      this.callbacks[type].push(callback);
 090  }
 091   
 092  /**
 093  * Record the name of the attribute being processed
 094  *
 095  * @param  {!string} attrName
 096  */
 097  Logger.prototype.setAttribute = function(attrName)
 098  {
 099      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  }