This is a documentation subpage for Modul:Debug/class. It contains usage information, categories and other content that is not part of the original modul page. |
This module is rated as beta, and is ready for widespread use. It is still new and should be used with some caution to ensure the results are as expected. |
This is a Class Module. It implements a class in Lua using Module:Middleclass. This class provides methods for creating and printing a debug log.
Usage[Quelltext bearbeiten]
local classDebug = require('Module:Debug/class')
local debugObject = classDebug:new('handlername')
debugObject:methodcall()
classDebug:staticMethodcall()
To use the debug log, create an object and provide a (unique) handler. Then log things via log(level, text) or classDebug:log(level, text, handler). At any time, you can print the log. When doing so, you can either
- print the whole debug log (over all available handlers)
- or only your specific handler
This class uses a static property to create the debug log, meaning all instances of class debug (all objects) write in one log (ie. a table). Later - depending whether you use the public or the static method - you print only 'your' entries (the one using your handler) or the whole log.
Besides a handler, all entries have a timestamp and a loglevel. On printout, all entries with a loglevel higher than a given number will be ommited.
Constructor[Quelltext bearbeiten]
new(handler)[Quelltext bearbeiten]
Creates a new Object for class debug.
- handler
- string, mandatory
- identifies your entries. should be unique over all used handlers/objects
- return
- object, of class debug
Methods[Quelltext bearbeiten]
Public methods[Quelltext bearbeiten]
__tostring()[Quelltext bearbeiten]
Returns a string representation of your debug log (all entries identified by your handler). Uses default debug level and default outputtype.
- return
- string, representation of itself
log(level, text)[Quelltext bearbeiten]
Creates a log entry.
- level
- integer, mandatory
- defines the log-level of the entry. the lower, the more important.
- text
- string, mandatory
- the actual log entry
- return
- void
printLog(level, outputtype)[Quelltext bearbeiten]
Prints all log entries having the same handler as this specific object. Not provided parameters will be defaulted. See static properties.
- level
- integer, suggested
- specifies which log entries will be printed in the log. all entries with a level higher than this number will be omitted.
- outputtype
- string, suggested
- formats the log. supported types are 'plain', 'ol', 'ul', 'pre'
- return
- string, formatted and filtered debug log
Static methods[Quelltext bearbeiten]
classDebug:log(level, text, handler)[Quelltext bearbeiten]
Creates a log entry. Can be called by other (static) methods without having a debug object at hand.
- level
- integer, mandatory
- defines the log-level of the entry. the lower, the more important.
- text
- string, mandatory
- the actual log entry
- handler
- string, suggested
- helps to identify the log entry. works just like the handler you create when instanciating an object of this class
- return
- void
classDebug:printLog(level, outputtype)[Quelltext bearbeiten]
Prints all log entries (effectively doing the same as the public method printLog(level, outputtype) only without the handler restriction). Not provided parameters will be defaulted. See static properties
- level
- integer, suggested
- specifies which log entries will be printed in the log. all entries with a level higher than this number will be omitted.
- outputtype
- string, suggested
- formats the log. supported types are 'plain', 'ol', 'ul', 'pre'
- return
- string, formatted and filtered debug log
Private methods[Quelltext bearbeiten]
none
Properties[Quelltext bearbeiten]
static[Quelltext bearbeiten]
- _debugLog
- table, holds all debug entries
- _defaultDebugLevel
- integer, default log level for printLog methods if none is provided
- _defaultOutputType
- string, default output format for printLog methods if none is provided
- _LANG
- object, mw.language.new( 'de' ) used for timestamp format in debug log
private[Quelltext bearbeiten]
Note: all private properties are stored in table _private[self]. _private is a static array that is indexed by self, so the table _private[self] holds all properties for instance self.
- handler
- 'my' log entry handler with which this object marks all entries it loggs.