API Docs for: 1.4.0
Show:

Kiwi.Utils.Log Class

Defined in: src\utils\Log.ts:10
Module: Utils.
Parent Module: Kiwi

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]
)

Defined in src\utils\Log.ts:10

Parameters:

  • [params] Object optional
  • [options.recording=true] Boolean optional

    If the logs should be recorded.

  • [options.display=true] Boolean optional

    If the logs should be displayed or not.

  • [options.enabled=true] Boolean optional

    If the Logger is enabled at all.

  • [options.maxRecordings=Infinity] Number optional

    The maximum number of recordings to have at a single time.

Methods

_execute

(
  • method
  • context
  • messages
  • [force=false]
)
private

Executes a particular array of messages using a method passed. Takes into account the 'display' property before executing.

Parameters:

  • method Any

    The method that should be used to log the messages. Generally a console method.

  • context Any

    The context that the method should be executed in. Generally set to the console.

  • messages Array
  • [force=false] Array optional

_filterTags

(
  • tags
  • [tagFilters=this.tagFilters]
)
Boolean private

Defined in src\utils\Log.ts:254

Available since 1.3.0

Returns true if the all of the tags passed also occur in the tag filters. This is used to filter out messages by their tags.

Parameters:

  • tags Array

    A list of tags, which need to occur in the tag filters

  • [tagFilters=this.tagFilters] Array optional

    A list of tags. Tags need to

Returns:

Boolean:

Tags match the tag filters, and so if the message would be allowed to execute.

_show

(
  • recording
  • tags
)
Boolean private

Method that displays a particular recording passed.

Parameters:

  • recording Object
  • tags Array

Returns:

Boolean:

If the recording was displayed or not.

addFilter

(
  • [...args]
)
public

Defined in src\utils\Log.ts:503

Available since 1.3.0

Adds a tag to the list of tag filters. Any messages that do not have the tags in the tagFilters list will not be displayed.

Parameters:

  • [...args] Any optional

    Tags to add to the filters list.

clearRecordings

(
  • [start=0]
  • [end]
)
public

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]
)
public

Logs a message using the 'console.error' method. Arguments starting with a '#' symbol are given that value as a tag.

Parameters:

  • [..args] Any optional

    The data you would like to log.

getTagsFromArray

(
  • strings
)
Array public

Accepts an array of strings and returns a new array consisting of all elements considered as a tag.

Parameters:

  • strings Array

Returns:

Array:

Elements of the array considered as tags

log

(
  • [..args]
)
public

Logs a message using the 'console.log' method. Arguments starting with a '#' symbol are given that value as a tag.

Parameters:

  • [..args] Any optional

    The data you would like to log.

recordMessage

(
  • message
  • [tags=[]
  • [logMethod=console.log]
)
public

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

removeFilter

(
  • [...args]
)
public

Defined in src\utils\Log.ts:516

Available since 1.3.0

Removes a tag to the list of tag filters. Any messages that do not have the tags in the tagFilters list will not be displayed.

Parameters:

  • [...args] Any optional

    Tags to be remove from the filters list.

setDefaultsFromParams

(
  • [params]
  • [options.recording=true]
  • [options.display=true]
  • [options.enabled=true]
  • [options.maxRecordings=Infinity]
)
public

Defined in src\utils\Log.ts:37

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 optional

    If the logs should be recorded.

  • [options.display=true] Boolean optional

    If the logs should be displayed or not.

  • [options.enabled=true] Boolean optional

    If the Logger is enabled at all.

  • [options.maxRecordings=Infinity] Number optional

    The maximum number of recordings to have at a single time.

showAll

(
  • [...args]
)
public

Displays all recordings. Ignores the tag filters.

Parameters:

  • [...args] Any optional

    Any tags that the recordings must have.

showErrors

(
  • [...args]
)
public

Displays all errors recorded. Ignores the tag filters.

Parameters:

  • [...args] Any optional

    Any tags that the recordings must have.

showLast

(
  • [...args]
)
public

Displays the last recording matching the tags passed. Ignores the tag filters.

Parameters:

  • [...args] Any optional

    Any tags that the recordings must have.

showLogs

(
  • [...args]
)
public

Displays all logs recorded. Ignores the tag filters.

Parameters:

  • [...args] Any optional

    Any tags that the recordings must have.

showTimePeriod

(
  • [start=0]
  • [end=Infinity]
  • [tags]
)
public

Displays a series of recordings within a time period passed. Time recorded is in milliseconds. Ignores the tag filters.

Parameters:

  • [start=0] Number optional
  • [end=Infinity] Number optional
  • [tags] Array optional

    An tags that the recordings must have.

showWarnings

(
  • [...args]
)
public

Displays all warnings recorded. Ignores the tag filters.

Parameters:

  • [...args] Any optional

    Any tags that the recordings must have.

warn

(
  • [..args]
)
public

Logs a message using the 'console.warn' method. Arguments starting with a '#' symbol are given that value as a tag.

Parameters:

  • [..args] Any optional

    The data you would like to log.

Properties

display

Boolean public

Defined in src\utils\Log.ts:95

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

Defined in src\utils\Log.ts:74

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

Defined in src\utils\Log.ts:85

If messages should be recorded or not.

Default: true

recordings

Array private

A list containing all messages recorded.

tagFilters

Array public

Defined in src\utils\Log.ts:106

Available since 1.3.0

A list of tags which any message recorded needs to match in-order to be displayed. This helps when debugging systems with lots of messages, without removing every log.