Modul:Debug/class/doc

This is [[MediaWiki:Tagline]]. Set to <code>display:none</code> by chameleon skin.
< Modul:Debug‎ | class
Version vom 23. Dezember 2015, 22:59 Uhr von imported>Oetterer
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Wechseln zu:Navigation, Suche

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

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

new(handler)

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

Public methods

__tostring()

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)

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)

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

classDebug:log(level, text, handler)

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)

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

none

Properties

static

_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

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.