Logger


Purpose

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 Hybrid Container'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);

Note

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.

Module

This object belongs to the Base product module.

Constants

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.

Name Description Value
window.launchbox.Logger.logLevel.SILENT

Denotes the SILENT log level.

No logs from the web application or the native code are returned.

0
window.launchbox.Logger.logLevel.ERROR Denotes the ERROR log level. 1
window.launchbox.Logger.logLevel.WARNING Denotes the WARNING log level. 2
window.launchbox.Logger.logLevel.INFO Denotes the INFO log level. 3
window.launchbox.Logger.logLevel.DEBUG Denotes the DEBUG log level. 4
window.launchbox.Logger.logLevel.VERBOSE

Denotes the VERBOSE log level.

Used solely for development purposes, returns all possible logs from the native code.

5

Note

Log levels are cumulative, therefore, when set to INFO level, the Logger API stores logs for INFO, WARNING and ERROR levels.

Attributes

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

Note

All attribute settings are persisted between restarts.

Methods

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.

clearLogFile

Removes any logs that have been stored in the files.

Legal notice | Copyright © 2016 and Confidential to Pegasystems Inc. All rights reserved
PDN | Hybrid Container | Feedback
Advanced...