Reference Source
public class | source

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

debug(message: string)

Logs a message at DEBUG level

public

debugWithMetadata(message: string, metadata: Object)

Logs a message at DEBUG level with additional metadata.

public

error(message: string)

Logs a message at ERROR level

public

errorWithMetadata(message: string, metadata: Object)

Logs a message at ERROR level with additional metadata.

public

Get the current value of the capture flag, indicating that the Logger is recording log calls persistently.

public

Get the current list of filters.

public

async getLevel(): Promise<string>

Get the current Logger level.

public

Get the current setting for the max file size threshold.

public

info(message: string)

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

setLevel(level: string)

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

trace(message: string)

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

warn(message: string)

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 static get DEBUG: string source

public static get ERROR: string source

public static get FATAL: string source

public static get INFO: string source

public static get LOG: string source

public static get TRACE: string source

public static get WARN: string source

Public Constructors

public constructor() source

Public Members

public logTag: * source

Public Methods

public debug(message: string) source

Logs a message at DEBUG level

Params:

NameTypeAttributeDescription
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.

Params:

NameTypeAttributeDescription
message string

The message to log

metadata Object

Any additional metadata to log.

public error(message: string) source

Logs a message at ERROR level

Params:

NameTypeAttributeDescription
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.

Params:

NameTypeAttributeDescription
message string

The error message to log

metadata Object

Any additional metadata to log.

public async getCapture(): Promise<boolean> source

Get the current value of the capture flag, indicating that the Logger is recording log calls persistently.

Return:

Promise<boolean>

true, if logging is enabled, false otherwise.

public async getFilters(): Promise<Object> source

Get the current list of filters.

Return:

Promise<Object>

The current list of filters in the form of {"packageName" : "LEVEL"}

public async getLevel(): Promise<string> source

Get the current Logger level.

Return:

Promise<string>

A string representation of the current Logging level. Possible values are TRACE, DEBUG, LOG, INFO, WARN, ERROR, FATAL. The default value is FATAL.

public async getMaxFileSize(): Promise<number> source

Get the current setting for the max file size threshold.

Return:

Promise<number>

The current threashold of the maximum file size.

public info(message: string) source

Logs a message at INFO level

Params:

NameTypeAttributeDescription
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.

Params:

NameTypeAttributeDescription
message string

The information message to log

metadata Object

Any additional metadata to log.

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:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
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.

Params:

NameTypeAttributeDescription
message string

The trace message to log

metadata Object

Any additional metadata to log.

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:

NameTypeAttributeDescription
message string

The warning message to log.

public warnWithMetadata(message: string, metadata: Object) source

Logs a message at WARN level with additional metadata. The metadata is available as custom fields while creating custom charts on the MobileFirst Analytics Console.

Params:

NameTypeAttributeDescription
message string

The warning message to log

metadata Object

Any additional metadata to log.