Kiwi.Utils.Log Class
A utilty class used to add management functionality to common console methods. You can use this class by either creating a new instance, or using the instance at the namespace 'Kiwi.Log'.
log/error/warn methods contained on this class function just like their 'console' equivalents except that:
- You can assign a tag to message by adding a '#' symbol to the front of a parameter. Example: this.log('Hi', '#welcome');
- Messages can have multiple tags. Example: this.log('Hi', '#welcome', '#greeting');
- Messages are recorded (by default) and you can then search through any messages saved.
You can use the 'show' commands to search through recordings and find specific messages.
Constructor
Kiwi.Utils.Log
-
[params]
-
[options.recording=true]
-
[options.display=true]
-
[options.enabled=true]
-
[options.maxRecordings=Infinity]
Parameters:
-
[params]
Object optional -
[options.recording=true]
Boolean optionalIf the logs should be recorded.
-
[options.display=true]
Boolean optionalIf the logs should be displayed or not.
-
[options.enabled=true]
Boolean optionalIf the Logger is enabled at all.
-
[options.maxRecordings=Infinity]
Number optionalThe maximum number of recordings to have at a single time.
Item Index
Methods
Methods
_execute
-
method
-
context
-
messages
-
[force=false]
Executes a particular array of messages using a method passed. Takes into account the 'display' property before executing.
Parameters:
-
method
AnyThe method that should be used to log the messages. Generally a console method.
-
context
AnyThe context that the method should be executed in. Generally set to the console.
-
messages
Array -
[force=false]
Array optional
_show
-
recording
-
tags
Method that displays a particular recording passed.
Parameters:
-
recording
Object -
tags
Array
Returns:
If the recording was displayed or not.
clearRecordings
-
[start=0]
-
[end]
Removes recordings from the list. Goes from the oldest to newest. By not passing any parameters, the entire log will be cleared.
Parameters:
-
[start=0]
Number optional -
[end]
Number optional
error
-
[..args]
Logs a message using the 'console.error' method. Arguments starting with a '#' symbol are given that value as a tag.
Parameters:
-
[..args]
Any optionalThe data you would like to log.
getTagsFromArray
-
strings
Accepts an array of strings and returns a new array consisting of all elements considered as a tag.
Parameters:
-
strings
Array
Returns:
Elements of the array considered as tags
log
-
[..args]
Logs a message using the 'console.log' method. Arguments starting with a '#' symbol are given that value as a tag.
Parameters:
-
[..args]
Any optionalThe data you would like to log.
recordMessage
-
message
-
[tags=[]
-
[logMethod=console.log]
Saves a message to the 'recordings' array. That message can then be retrieved later using the 'show' methods.
Parameters:
-
message
String -
[tags=[]
String optional -
[logMethod=console.log]
String optional
setDefaultsFromParams
-
[params]
-
[options.recording=true]
-
[options.display=true]
-
[options.enabled=true]
-
[options.maxRecordings=Infinity]
Sets the log properties based on a object passed. This method is used to set the properties on the Log based on gameoptions passed at game creation.
Parameters:
-
[params]
Object optional -
[options.recording=true]
Boolean optionalIf the logs should be recorded.
-
[options.display=true]
Boolean optionalIf the logs should be displayed or not.
-
[options.enabled=true]
Boolean optionalIf the Logger is enabled at all.
-
[options.maxRecordings=Infinity]
Number optionalThe maximum number of recordings to have at a single time.
showAll
-
[...args]
Displays all recordings.
Parameters:
-
[...args]
Any optionalAny tags that the recordings must have.
showErrors
-
[...args]
Displays all errors recorded.
Parameters:
-
[...args]
Any optionalAny tags that the recordings must have.
showLast
-
[...args]
Displays the last recording matching the tags passed.
Parameters:
-
[...args]
Any optionalAny tags that the recordings must have.
showLogs
-
[...args]
Displays all logs recorded.
Parameters:
-
[...args]
Any optionalAny tags that the recordings must have.
showTimePeriod
-
[start=0]
-
[end=Infinity]
-
[tags]
Displays a series of recordings within a time period passed. Time recorded is in milliseconds
Parameters:
-
[start=0]
Number optional -
[end=Infinity]
Number optional -
[tags]
Array optionalAn tags that the recordings must have.
showWarnings
-
[...args]
Displays all warnings recorded.
Parameters:
-
[...args]
Any optionalAny tags that the recordings must have.
warn
-
[..args]
Logs a message using the 'console.warn' method. Arguments starting with a '#' symbol are given that value as a tag.
Parameters:
-
[..args]
Any optionalThe data you would like to log.
Properties
display
Boolean
public
If the log, warn, and error methods should display when executed or not. You may want to set this to 'false' when releasing a game.
Default: true
enabled
Boolean
public
If the log, warn, or error messages should function at all. When set to false messages won't display or be recorded.
Default: true
lastMessageTime
Number
public
The time (in milliseconds) of the last recording.
maxRecordings
Number
public
The maximum number of recordings to be kept at once.
Default: Infinity
numRecordings
Number
public
The number of recordings that have been saved. Same as the recordings length, and won't go above the 'maxRecordings'.
record
Boolean
public
If messages should be recorded or not.
Default: true
recordings
Array
private
A list containing all messages recorded.