Logger Module

API Docs for: 1.0.1
Show:

LoggerModule Class

Module: Readme

Methods

areAllGroupsEnabled

() Boolean

Available since 1.0.0

Returns true if logging for all groups is enabled, false otherwise.

Returns:

Boolean:

debug

(
  • params
)
Void

Available since 1.0.0

Logs a message with a millisecond timestamp at the DEBUG log level, optionally within a logging group.

Logger.debug({ group: 'group', msg: 'msg' });

is equivalent to

Logger.log({ level: Logger.DEBUG, group: 'group', msg: 'msg' });

Note that this method can take 1 or 2 arguments, and the single argument can be a string (which will be interpreted as the message to be logged) or an object (which can have 1 or 2 properties itself).

Parameters:

  • params Object
    • [group] String optional
    • msg String

Returns:

Void:

debug

(
  • [group]
  • message
)
Void

Available since 1.0.0

Logs a message with a millisecond timestamp at the DEBUG log level, optionally within a logging group.

Logger.debug([group, ] msg)

is equivalent to

Logger.log(Logger.DEBUG, [group, ] msg)

Note that this method can take 1 or 2 arguments, and the single argument can be a string (which will be interpreted as the message to be logged) or an object (which can have 1 or 2 properties itself).

Parameters:

  • [group] String optional
  • message String

Returns:

Void:

deleteErrorFiles

() Void

Available since 1.0.0

Deletes all error files.

Use the startErrorMonitoring function to start the collection of error information into files, or the getErrorFileInfo function to retrieve information about the currently available error files.

Returns:

Void:

deleteLogFiles

() Void

Available since 1.0.0

Deletes all log files. If log collection is running when this function is called, log collection will be temporarily stopped while the files are being deleted and then restarted. This means that a new (set of) log files will be created immediately after the existing files are deleted. If this is not desired, stop log collection using the stopLogCollection function before calling deleteLogFiles.

Returns:

Void:

disableAllGroups

() Void

Available since 1.0.0

Turns off logging for all groups. See also enableGroups, enableAllGroups, and disableGroups.

Returns:

Void:

disableGroups

(
  • [group*]
)
Void

Available since 1.0.0

Turns off logging for the specified groups. See also enableGroups, enableAllGroups, and disableAllGroups.

Parameters:

  • [group*] String optional

Returns:

Void:

enableAllGroups

() Void

Available since 1.0.0

Turns on logging for all groups. See also enableGroups, disableGroups, and disableAllGroups.

Returns:

Void:

enableGroups

(
  • [group*]
)
Void

Available since 1.0.0

Turns on logging for the specified groups. See also disableGroups, enableAllGroups, and disableAllGroups.

Parameters:

  • [group*] String optional

Returns:

Void:

error

(
  • [group]
  • message
)
Void

Available since 1.0.0

Logs a message with a millisecond timestamp at the ERROR log level, optionally within a logging group.

Logger.error([group, ] msg)

is equivalent to

Logger.log(Logger.ERROR, [group, ] msg)

Note that this method can take 1 or 2 arguments, and the single argument can be a string (which will be interpreted as the message to be logged) or an object (which can have 1 or 2 properties itself).

Parameters:

  • [group] String optional
  • message String

Returns:

Void:

flushLogs

() Void

Available since 1.0.0

Writes all the currently available log messages into the log file. This is potentially useful because log collection runs periodically, by default every 10 seconds. Call this function if you don't want to wait for the next regularly scheduled instance of log collection.

This operation is synchronous on iOS, but for compatibility with Android, the flushCompleted event is fired when the operation completes.

Does nothing (although flushCompleted is still fired) if log collection is not running; see startLogCollection.

Returns:

Void:

getEnabledGroups

() Array of Strings

Available since 1.0.0

Returns the groups that are currently enabled for logging. See also the areAllGroupsEnabled; if logging for all groups is enabled, then all messages will be logged regardless of what groups this function returns.

Returns:

Array of Strings:

getErrorFileInfo

() Array of Objects

Available since 1.0.0

Returns an array of objects that describe the currently available files that capture crashes and exceptions.

Use the startErrorMonitoring method to start the collection of error information into files, or the deleteErrorFiles method to delete all the error info files at once.

Returns:

Array of Objects:

Each object has a file (a Titanium File object) and an errorTime (String) property.

getLogCollectionStatus

() Number final

Available since 1.0.0

Shows the status of log collection. See the LOG_COLLECTION_STOPPED, LOG_COLLECTION_PAUSED, and LOG_COLLECTION_STARTED, constants.

Returns:

Number:

getLogFileInfo

() Array of Objects

Available since 1.0.0

Returns an array of objects that describe the currently available log files.

Returns:

Array of Objects:

Each object has a file (a Titanium File object), a startTime (String), a buffer (String), and a seqNum (Number) property. The buffer property is present for compatibility with Android; iOS only has one buffer so this property is always set to "main" on this platform.

info

(
  • [group]
  • message
)
Void

Available since 1.0.0

Logs a message with a millisecond timestamp at the INFO log level, optionally within a logging group.

Logger.info([group, ] msg)

is equivalent to

Logger.log(Logger.INFO, [group, ] msg)

Note that this method can take 1 or 2 arguments, and the single argument can be a string (which will be interpreted as the message to be logged) or an object (which can have 1 or 2 properties itself).

Parameters:

  • [group] String optional
  • message String

Returns:

Void:

info

(
  • params
)
Void

Available since 1.0.0

Logs a message with a millisecond timestamp at the INFO log level, optionally within a logging group.

Logger.info({ group: 'group', msg: 'msg' });

is equivalent to

Logger.log({ level: Logger.INFO, group: 'group', msg: 'msg' });

Note that this method can take 1 or 2 arguments, and the single argument can be a string (which will be interpreted as the message to be logged) or an object (which can have 1 or 2 properties itself).

Parameters:

  • params Object
    • [group] String optional
    • msg String

Returns:

Void:

isLogCollectionRunning

() Boolean

Available since 1.0.0

Determines whether log collection is currently running.

Returns:

Boolean:

log

(
  • [level]
  • [group]
  • message
)
Void

Available since 1.0.0

Logs a message with a millisecond timestamp, optionally at the specified log level and/or within a logging group (see enableGroups and disableGroups methods).

Note that this method can take 1, 2, or 3 arguments, and the single argument can be a string (which will be interpreted as the message to be logged) or an object (which can have 1, 2, or 3 properties itself).

Parameters:

  • [level] Number optional
  • [group] String optional
  • message String

Returns:

Void:

log

(
  • params
)
Void

Available since 1.0.0

Logs a message with a millisecond timestamp, optionally at the specified log level and/or within a logging group (see enableGroups and disableGroups methods).

Note that this method can take 1, 2, or 3 arguments, and the single argument can be a string (which will be interpreted as the message to be logged) or an object (which can have 1, 2, or 3 properties itself).

Parameters:

  • params Object
    • [level] Number optional
    • [group] String optional
    • msg String

Returns:

Void:

logException

(
  • exception
)
Void

Available since 1.0.0

Logs a JavaScript exception into an error file. Call this function after you caught an exception in JavaScript, with the caught exception object as the parameter.

Parameters:

  • exception Exception

Returns:

Void:

pauseLogCollection

() Void

Available since 1.0.0

Pauses log collection. See also resumeLogCollection.

Returns:

Void:

resumeLogCollection

() Void

Available since 1.0.0

Resumes log collection. See also pauseLogCollection.

Returns:

Void:

startErrorMonitoring

() Boolean

Available since 1.0.0

Starts error monitoring and the collection of related information into files.

The type of events handled by this function is slighthy different on iOS and Android. On iOS, information about fatal signals, exceptions that trigger a fatal signal, and exceptions caught by Titanium is collected. On Android, information about uncaught exceptions and exceptions caught by the Titanium framework is collected.

Capturing information about exceptions caught in JavaScript happens independently from this function. To capture information related to an exception caught in JavaScript, call logException.

On iOS, The information for fatal signal (hard crash) will be available the next time the app restarts after the crash.

Once error monitoring is started, it can only be turned off by restarting the app (and not calling this method when it does restart). If you want to give control to the user whether error monitoring should be running or not, you can provide a switch on the GUI and ask the user to restart the app when the switch is turned off.

Use the getErrorFileInfo method to retrieve information about the currently available error files, or the deleteErrorFiles method to delete all the error info files at once.

Returns:

Boolean:

True if error monitoring was started successfully, false otherwise.

startLogCollection

(
  • [interval=10]
)
Void

Available since 1.0.0

Starts log collection into a log file. See also stopLogCollection.

Parameters:

  • [interval=10] Number optional

    Specifies, in seconds, how often the console log is saved into the log file. Defaults to 10. Must be at least 1.

Returns:

Void:

stopLogCollection

() Void

Available since 1.0.0

Stops log collection into a log file. See also startLogCollection.

Returns:

Void:

trace

(
  • params
)
Void

Available since 1.0.0

Logs a message at the TRACE log level, optionally within a logging group.

Logger.trace({ group: 'group', msg: 'msg' });

is equivalent to

Logger.log({ level: Logger.TRACE, group: 'group', msg: 'msg' });

Note that this method can take 1 or 2 arguments, and the single argument can be a string (which will be interpreted as the message to be logged) or an object (which can have 1 or 2 properties itself).

Parameters:

  • params Object
    • [group] String optional
    • msg String

Returns:

Void:

trace

(
  • [group]
  • message
)
Void

Available since 1.0.0

Logs a message at the TRACE log level, optionally within a logging group.

Logger.trace([group, ] msg)

is equivalent to

Logger.log(Logger.TRACE, [group, ] msg)

Note that this method can take 1 or 2 arguments, and the single argument can be a string (which will be interpreted as the message to be logged) or an object (which can have 1 or 2 properties itself).

Parameters:

  • [group] String optional
  • message String

Returns:

Void:

warning

(
  • params
  • [group]
  • message
)
Void

Available since 1.0.0

Logs a message with a millisecond timestamp at the ERROR log level, optionally within a logging group.

Logger.error({ group: 'group', msg: 'msg' });

is equivalent to

Logger.log({ level: Logger.ERROR, group: 'group', msg: 'msg' });

Note that this method can take 1 or 2 arguments, and the single argument can be a string (which will be interpreted as the message to be logged) or an object (which can have 1 or 2 properties itself).

Parameters:

  • params Object
    • [group] String optional
    • msg String
  • [group] String optional
  • message String

Returns:

Void:

warning

(
  • params
)
Void

Available since 1.0.0

Logs a message with a millisecond timestamp at the WARNING log level, optionally within a logging group.

Logger.warning({ group: 'group', msg: 'msg' });

is equivalent to

Logger.log({ level: Logger.WARNING, group: 'group', msg: 'msg' });

Note that this method can take 1 or 2 arguments, and the single argument can be a string (which will be interpreted as the message to be logged) or an object (which can have 1 or 2 properties itself).

Parameters:

  • params Object
    • [group] String optional
    • msg String

Returns:

Void:

Properties

logLevel

Number

Available since 1.0.0

The global log level. Messages that are logged with a log level themselves will only be printed if their log level is lower than or equal than the global log level. Defaults to TRACE.

maxLogFileSize

Number

Available since 1.0.0

The maximum size of each log file, in bytes. Defaults to 1,000,000. The smallest accepted value for this property is 10,000.

maxSessionLogFileCount

Number

Available since 1.0.0

The maximum number of log files per session. Defaults to 3.

maxTotalLogFileCount

Number

Available since 1.0.0

The maximum number of log files in total. Defaults to 6.

printMilliseconds

Boolean

Available since 1.0.0

Specifies whether the log function includes a millisecond timestamp by default. The default value is false.

Including an extra millisecond timestamp is an iOS only feature, which can be helpful for performance measurements. On Android, the system timestamps already include milliseconds.

Constants

DEBUG

Number

Available since 1.0.0

Use this constant to set the logLevel property or the level parameter of the log method.

DEBUG1

Number

Available since 1.0.0

Use this constant to set the logLevel property or the level parameter of the log method.

DEBUG2

Number

Available since 1.0.0

Use this constant to set the logLevel property or the level parameter of the log method.

DEBUG3

Number

Available since 1.0.0

Use this constant to set the logLevel property or the level parameter of the log method.

DEBUG4

Number

Available since 1.0.0

Use this constant to set the logLevel property or the level parameter of the log method.

DEBUG5

Number

Available since 1.0.0

Use this constant to set the logLevel property or the level parameter of the log method.

DEBUG6

Number

Available since 1.0.0

Use this constant to set the logLevel property or the level parameter of the log method.

DEBUG7

Number

Available since 1.0.0

Use this constant to set the logLevel property or the level parameter of the log method.

DEBUG8

Number

Available since 1.0.0

Use this constant to set the logLevel property or the level parameter of the log method.

DEBUG9

Number

Available since 1.0.0

Use this constant to set the logLevel property or the level parameter of the log method.

ERROR

Number

Available since 1.0.0

Use this constant to set the logLevel property or the level parameter of the log method.

INFO

Number

Available since 1.0.0

Use this constant to set the logLevel property or the level parameter of the log method.

LOG_COLLECTION_PAUSED

Number

Available since 1.0.0

This is one of the possible values of the LoggerModule/logCollectionStatus:property property. It indicates that log collection has been paused.

LOG_COLLECTION_STARTED

Number

Available since 1.0.0

This is one of the possible values of the LoggerModule/logCollectionStatus:property property. It indicates that log collection has been started.

LOG_COLLECTION_STOPPED

Number

Available since 1.0.0

This is one of the possible values of the LoggerModule/logCollectionStatus:property property. It indicates that log collection has been stopped (or never started).

NONE

Number

Available since 1.0.0

Use this constant to set the logLevel property. This is the alias for a log level so high that none of the messegase that have a log level will be printed.

TRACE

Number

Available since 1.0.0

Use this constant to set the logLevel property or the level parameter of the log method.

WARNING

Number

Available since 1.0.0

Use this constant to set the logLevel property or the level parameter of the log method.

Events

flushCompleted

Available since 1.0.0

This event is fired when the flushLogs operation completes.