mp-debugger
v0.0.1
Published
Simple modular object to debbug code (ex. showing in console, creating logs etc.)
Downloads
1
Readme
#Debugger Simple modular object to debbug code (ex. showing in console, creating logs etc.)
Usage
Include js combined file.
<script src="dist/debugger.js"></script>
Add code before your js files to avoid error when you don`t include debbuger files in production version.
if(typeof DEBUGGER == "undefined") DEBUGGER = {run: function(){},addMethod: function(){}};
Run debbuger method
DEBUGGER.run(methodName,vars[,moduleName]);
Arguments:
| Argument | Type | Description
|--------|---------|------------
| methodName
| string
| Method name
| vars
| mixed
| Vars which are passed to method
| moduleName
| string
| Module name from you call debugger method- is used to simply know where you call method- e.g. method log show in console this property
Example
DEBUGGER.run("info","Some message");
Add methods
To add your own methods call addMethod on object.
DEBUGGER.addMethod(methodName,content [, requiredvars]);
Arguments:
| Argument | Type | Description
|--------|---------|------------
| methodName
| string
| Method name
| content
| function
| Method, argument is 'vars' which are passed in call method
| requiredvars
| array
| All required vars which must contain 'vars' object, not required when you pass only one var
If you dont pass object in call function, debugger create object with 'default' property. Futhermore add 'moduleNameCall' property- moduleName in call method.
Example:
DEBUGGER.addMethod("log", function(Vars){
this.print(Vars.moduleNameCall, Vars.default, "log");
return true; // all method must return bool var
});
...
DEBUGGER.run("log","Some message"); // string "Some message" is added to Vars.default property
Methods utils
In 'this' object you can use utils methods like:
this.print()
Print messages in console, special debug bar or log file.
this.print(module, message[, type='log', plain=false]);
| Argument | Type | Default | Description
|--------|---------|-------|---------
| module
| string
| - |Module name
| message
| string
| - |Show error in console
| type
| string
| log
|Message type {log,warn,info,error}
| plain
| bool
| false |Don`t print module name
this.setObject()
Save an object for later.
this.setObject(key, object[, methodName='debuger:setObject']);
| Argument | Type | Default | Description
|--------|---------|-------|---------
| key
| string
| - | Key
| object
| mixed
| - | Object to save
| methodName
| string
| debuger:setObject
| Message type {log,warn,info,error}
this.getObject()
Get previously saved objects.
this.getObject(key, [, methodName='debuger:setObject']);
| Argument | Type | Default | Description
|--------|---------|-------|---------
| key
| string
| - | Key
| methodName
| string
| debuger:setObject
| Method name
this.deleteObject()
Delete an saved object.
this.deleteObject(key [, methodName='debuger:setObject']);
| Argument | Type | Default | Description
|--------|---------|-------|---------
| key
| string
| - | Key
| methodName
| string
| debuger:deleteObject
| Method name
Available default methods
List of methods:
| Method | Arguments | Description
|--------|-------------|-------------
| log
| message
(string) | Show log in console |
| error
| message
(string) | Show error in console
| warn
| message
(string) | Show warn in console
| info
| message
(string) | Show info in console
| startTimer
| id
(string) | Start timer with passed id
| stopTimer
| id
(string) | Stop timer with passed id and return time in ms
| isLibrary
| Library
(string) | Check if in global scobe is attached library
To do
- Add debugger method where you can show messages, errors etc... Now you must open console.
- Add method setConfig which you can set if message shoud show in console or in bar.
- Add some aliases to different libraries (like fps graph etc).
- Add method to log and write in file all messages.