The Logger API allows changing the current logging level and enables access to the local log file. In consequence, it allows creating a web application that is able to retrieve log details and send them via e-mail or post to the server.
The object can be accessed using the launchbox.Logger
reference.
To use the API it is necessary to set the attributes mentioned in a table below once the
onLaunchboxLoaded
method was called.
Log information originates from the following two sources:
the web application (via the standard console logger),
the AMP Hybrid Client's native code, including custom modules.
In order to use the API you need to call the following from the web application:
console.error("This is an error message #" + messageId); console.warn("This is a warning message #" + messageId); console.info("This is a info message #" + messageId); console.debug("This is a debug message #" + messageId);
The console.log
level is equivalent to the console.info
one.
The above log levels correspond to the log levels mentioned in the "Constants" section below. Before they are stored in the console or written to a file, all JavaScript and native logs are filtered based on the log level setting. Refer to the Logger example article for a complete usage example.
The table lists the allowed log level constants predefined for the Logger
object. Log level definitions are in-line with the description given e.g. in the Android SDK
documentation.
Constant | Description |
---|---|
window.launchbox.Logger.logLevel.SILENT | Denotes the SILENT log level. No logs from the web application or the native code are returned. |
window.launchbox.Logger.logLevel.ERROR | Denotes the ERROR log level. |
window.launchbox.Logger.logLevel.WARNING | Denotes the WARNING log level. |
window.launchbox.Logger.logLevel.INFO | Denotes the INFO log level. |
window.launchbox.Logger.logLevel.DEBUG | Denotes the DEBUG log level. |
window.launchbox.Logger.logLevel.VERBOSE | Denotes the VERBOSE log level. Used solely for development purposes, returns all possible logs from the native code. |
Log levels are cumulative, therefore, when set to INFO level, the Logger API stores logs for INFO, WARNING and ERROR levels.
The attributes of the Logger object are listed below:
Attribute | Description | Type |
---|---|---|
logLevel | JavaScript property (get/set) accepting one of
window.launchbox.Logger.logLevel constants. It is used to decide what
logs are logged in the log file. By default it is set to
"window.launchbox.Logger.logLevel.INFO". |
string |
logToConsole | If set to "true", the Logger API prints messages to a system console (ASL/Logcat). By default it is set to "true". | boolean |
logToFile | If set to "true", the Logger API prints messages to a file. By default it is set to "false". | boolean |
totalDiskQuota | Sets the disk quota for storing logs in a file (in bytes). By default it is set to 20 MB. | int |
All attribute settings are persisted between restarts.
Name | Description |
---|---|
readLogTail | Returns a defined number of last log records in a string array. To operate, it requires the logToFile property to be set to "true". |
archiveLogs | Saves logs from given period to a text file, accessible by means of the Filesystem API. |
clearLog |
Removes any logs that have been stored in the files. |