WLLogger
WLLogger is a class for logging that provides some enhanced capability such as capturing log calls, package filtering, and log level control at both global and individual package scope.
It also provides a method call to send captured logs to the IBM MobileFirst Platform server.
Log file data is sent to the IBM MobileFirst Platform server when this class's send() method is called and the accumulated log size is greater than zero. When the log data is successfully uploaded, the persisted local log data is deleted.
When this Logger class's capture flag is turned on via setCapture(true) method call, all messages passed through this class's log methods will be persisted to store in the following JSON object format:
Example:
{
"timestamp" : "17-02-2013 13:54:27:123", // "dd-MM-yyyy hh:mm:ss:S"
"level" : "ERROR", // FATAL || ERROR || WARN || INFO || LOG || DEBUG || TRACE
"package" : "your_tag", // typically a class name, app name, or JavaScript object name
"msg" : "the message", // a helpful log message
"metadata" : {"hi": "world"}, // (optional) additional JSON metadata, appended via doLog API call
"threadid" : long // (optional) id of the current thread
}
Static Member Summary
Static Public Members | ||
public static get |
|
|
public static get |
|
|
public static get |
|
|
public static get |
|
|
public static get |
|
|
public static get |
|
|
public static get |
|
Constructor Summary
Public Constructor | ||
public |
|
Member Summary
Public Members | ||
public |
logTag: * |
Method Summary
Public Methods | ||
public |
Logs a message at DEBUG level |
|
public |
debugWithMetadata(message: string, metadata: Object) Logs a message at DEBUG level with additional metadata. |
|
public |
Logs a message at ERROR level |
|
public |
errorWithMetadata(message: string, metadata: Object) Logs a message at ERROR level with additional metadata. |
|
public |
async getCapture(): Promise<boolean> Get the current value of the capture flag, indicating that the Logger is recording log calls persistently. |
|
public |
async getFilters(): Promise<Object> Get the current list of filters. |
|
public |
Get the current Logger level. |
|
public |
async getMaxFileSize(): Promise<number> Get the current setting for the max file size threshold. |
|
public |
Logs a message at INFO level |
|
public |
infoWithMetadata(message: string, metadata: Object) Logs a message at INFO level with additional metadata. |
|
public |
send() Send the accumulated log data when the persistent log buffer exists and is not empty. |
|
public |
setCapture(capture: boolean) Global setting to turn persisting of log data passed to this class's log methods on or off. |
|
public |
setFilters(filter: Object) Filter on packages at and above designated LEVEL. |
|
public |
Set the level and above at which log messages should be saved/printed. |
|
public |
setMaxFileSize(sizeInBytes: number) Set the maximum size of the local log file. |
|
public |
Logs a message at TRACE level |
|
public |
traceWithMetadata(message: string, metadata: Object) Logs a message at TRACE level with additional metadata. |
|
public |
Get and apply the configuration from the IBM MobileFirst Platform Server. |
|
public |
Logs a message at WARN level |
|
public |
warnWithMetadata(message: string, metadata: Object) Logs a message at WARN level with additional metadata. |
Static Public Members
Public Constructors
public constructor() source
Public Members
public logTag: * source
Public Methods
public debug(message: string) source
Logs a message at DEBUG level
Params:
Name | Type | Attribute | Description |
message | string | The message to log. |
public debugWithMetadata(message: string, metadata: Object) source
Logs a message at DEBUG level with additional metadata. The metadata is available as custom fields while creating custom charts on the MobileFirst Analytics Console.
public error(message: string) source
Logs a message at ERROR level
Params:
Name | Type | Attribute | Description |
message | string | The error message to log. |
public errorWithMetadata(message: string, metadata: Object) source
Logs a message at ERROR level with additional metadata. The metadata is available as custom fields while creating custom charts on the MobileFirst Analytics Console.
public async getCapture(): Promise<boolean> source
Get the current value of the capture flag, indicating that the Logger is recording log calls persistently.
public async getMaxFileSize(): Promise<number> source
Get the current setting for the max file size threshold.
public info(message: string) source
Logs a message at INFO level
Params:
Name | Type | Attribute | Description |
message | string | The information message to log. |
public infoWithMetadata(message: string, metadata: Object) source
Logs a message at INFO level with additional metadata. The metadata is available as custom fields while creating custom charts on the MobileFirst Analytics Console.
public send() source
Send the accumulated log data when the persistent log buffer exists and is not empty. The data accumulates in the log buffer from the use of Logger with capture turned on.
public setCapture(capture: boolean) source
Global setting to turn persisting of log data passed to this class's log methods on or off.
Params:
Name | Type | Attribute | Description |
capture | boolean | True to turn on logging, false to turn it off. |
public setFilters(filter: Object) source
Filter on packages at and above designated LEVEL. This is a white list. Any package not listed in the filters will not be logged. Pass null or an empty HashMap parameter to remove filters and resume logging at the default LEVEL.
Params:
Name | Type | Attribute | Description |
filter | Object | set of filters and associated level (and above) to allow for logging |
public setLevel(level: string) source
Set the level and above at which log messages should be saved/printed. A null parameter value is ignored and has no effect.
Params:
Name | Type | Attribute | Description |
level | string | A string representation of the Logger level. Valid values are TRACE, DEBUG, LOG, INFO, WARN, ERROR, FATAL. You can use the properties defined in WLLogger as well. |
Example:
var homePageLogger = new WLLogger("HomePage");
homePageLogger.setCapture(true);
homePageLogger.setLevel (WLLogger.DEBUG);
homePageLogger.debug("User exited home page.");
public setMaxFileSize(sizeInBytes: number) source
Set the maximum size of the local log file. Once the maximum file size is reached, no more data will be appended. The file must then be sent to the server using the send() API.
Params:
Name | Type | Attribute | Description |
sizeInBytes | number | The maximum size of the file in number of bytes. The minimum is 10000. |
public trace(message: string) source
Logs a message at TRACE level
Params:
Name | Type | Attribute | Description |
message | string | The trace message to log. |
public traceWithMetadata(message: string, metadata: Object) source
Logs a message at TRACE level with additional metadata. The metadata is available as custom fields while creating custom charts on the MobileFirst Analytics Console.
public updateConfigFromServer() source
Get and apply the configuration from the IBM MobileFirst Platform Server. The configuration comes from the use of the "Config Profiles" tab in the IBM MobileFirst Platform administrative console.
public warn(message: string) source
Logs a message at WARN level
Params:
Name | Type | Attribute | Description |
message | string | The warning message to log. |