Skip to content

User Guide: SDKs > Volt MX Iris SDK > Using Log SDK

Volt MX Logger

Introduction

Volt MX Logger is introduced to persist logs based on six log levels:

  • Trace
  • Debug
  • Info
  • Warn
  • Error
  • Fatal

The logger feature provides three ways of providing logs to output: console, file and network. The logger feature is defined in the namespace voltmx.logger. Each log will be printed as per the below syntax:

 [LoggerInstanceName][AppID AppVersion][TimestampTimeZone][LogLevel][SessionID][ThreadInformation][DeviceId][DeviceOSInfo][FileName][ClassName][MethodName][LineNo]Message

Scope

The Volt MX Logger feature is available for Volt MX Iris, Android, iOS, and Windows 10.

Properties

voltmx.logger exposes the below properties:

currentLogLevel

currentLogLevel sets the log level of the logger to any of the six mentioned levels. setting to a certain level will allow the logs of that level and above to be persisted. For instance, if the currentLogLevel is set to Error, only the error and fatal log statements are printed.

SyntaxJavaScript: voltmx.logger.currentLogLevel
Possible ValuesThe below log levels may be set to the current log level: voltmx.logger.logLevel.ALL voltmx.logger.logLevel.NONE voltmx.logger.logLevel.TRACE voltmx.logger.logLevel.DEBUG voltmx.logger.logLevel.INFO voltmx.logger.logLevel.WARN voltmx.logger.logLevel.ERROR voltmx.logger.logLevel.FATAL
Default Valuevoltmx.logger.logLevel.NONE
Read or WriteYes (Read and Write)
JavaScript Examplevoltmx.logger.currentLogLevel = voltmx.logger.logLevel.DEBUG;

APIs

Multiple instances of the logger can be created using APIs. The console and the file can be activated as a part of the configuration, if required. The below APIs are introduced to create logger, activate persistors and generate the logs.

createFilePersistor()

The createFilePersistor() API is used to create the configuration for the file persistor. This configuration can be used with the loggerConfig object (For more information, refer addPersistor API).

Note: In Iris Android, if you want activate file persistor and view the logs in the file, you need to add WRITE_EXTERNAL_STORAGE under Permissions tab.

Signature JavaScript: createFilePersistor
Parameters N/A
Return Type The API return a fileConfig object. The below properties have been exposed on the file persistor.
JavaScript Example var persistor1 = new voltmx.logger.createFilePersistor(); persistor1.maxFileSize = 100; persistor1.maxNumberOfLogFiles = 15;
Platform Availability Available on IDE, Android, iOS, and Windows 10

maxFileSize

The maxFileSize API is used to define the maximum size of the files created in bytes.

SyntaxmaxFileSize
TypeNumber
Possible ValuesPositive Integer
Default Value10000
Read or WriteOnly Write
JavaScript Examplevar persistor1 = new voltmx.logger.createFilePersistor(); persistor1.maxFileSize = 10000;

maxNumberOfLogFiles

To define the maxNumberOfLogFiles the app can have at a maximum during any instant. The filePersistor is a rolling file appender i.e. the data of latest configured files is preserved.

SyntaxmaxNumberOfLogFiles
TypeNumber
Possible ValuesNon-zero, Positive Integer
Default Value10
Read or WriteOnly Write
JavaScript Examplevar persistor1 = new voltmx.logger.createFilePersistor(); persistor1.maxNumberOfLogFiles = 20;

createLoggerConfig()

CreateLoggerConfig() is used to create the configuration object for the logger. This object is used in the createNewLogger() API. The object has various properties exposed to define our configuration. To apply the configuration, you need to use setConfig() API . When you pass the object through createNewLogger() API , configuration object is immediately applied .

Signature Javascript: createLoggerConfig
Parameters N/A
Return Type The API returns a loggerConfig Object. All the properties are static and affect all the logger instances. The below properties have been exposed.
JavaScript Example Example 1: var loggerConfig = new voltmx.logger.createLoggerConfig(); Example 2: var loggerConfig = new voltmx.logger.createLoggerConfig(); loggerConfig.bytesLimit = 10000; loggerConfig.statementsLimit = 10; loggerConfig.timeFormat = "dd-MM-yyyy HH.mm.ss.SSS"; loggerConfig.timeZone = "UTC"; loggerConfig.overrideConfig = true; loggerConfig.logLevel= voltmx.logger.logLevel.INFO.value;
Platform Availability IDE, Android, iOS, and Windows 10

bytesLimit

The console logs will be printed as soon as the logging methods are invoked. It is performance intensive to persist the logs one by one on the file. The bytesLimit can be used to accumulate the logs until the bytesLimit is reached and then flushed onto the file.

SyntaxbytesLimit
TypeNumber
Possible ValuesAny positive integer
Default Value10000
Read or WriteOnly Write
JavaScript Examplevar loggerConfig = new voltmx.logger.createLoggerConfig(); loggerConfig.bytesLimit = 20000;

statementsLimit

The console logs will be printed as soon as the logging methods are invoked. It is performance intensive to persist the logs one by one on the file. The statementsLimit can be used to accumulate the logs until the specified number of statements are reached and then flushed onto the file.

SyntaxstatementsLimit
TypeNumber
Possible ValuesAny non-negative integer
Default Value20
Read or WriteOnly Write
JavaScript Examplevar loggerConfig = new voltmx.logger.createLoggerConfig(); loggerConfig.statementsLimit = 30;

timeFormat

Each log is printed in a specified format. The format includes the timestamp. This property is used to specify the syntax of the timeFormat.

SyntaxtimeFormat
TypeString
Possible ValuesAny valid time format pattern
Default Value"dd-mm-yyyy HH.mm.ss.SSS"
Read or WriteOnly Write
JavaScript Examplevar loggerConfig = new voltmx.logger.createLoggerConfig(); loggerConfig.timeFormat = "dd-MM-yyyy HH.mm.ss.SSS";

timeZone

Each log is printed in a specified format. The format includes the timestamp. This property is used to specify the syntax of the timeZone.

SyntaxtimeZone
TypeString
Possible ValuesUTC, LocalTime
Default ValueUTC
Read or WriteOnly Write
JavaScript Examplevar loggerConfig = new voltmx.logger.createLoggerConfig(); loggerConfig.timeZone = "UTC";

overrideConfig

All the properties are exposed by loggerConfig. Changing the property and using setConfig() API will affect all the logger instances created. overrideConfig is used to specify if the configuration should override the existing configuration.

SyntaxoverrideConfig
TypeBool
Possible ValuesTrue or False
Default ValueTrue
Read or WriteOnly Write
JavaScript Examplevar loggerConfig = new voltmx.logger.createLoggerConfig(); loggerConfig.overrideConfig = false;

logLevel

The logLevel property works similar to currentLogLevel property. There are six log levels in the logLevel property.

SyntaxlogLevel
Possible Valuesvoltmx.logger.logLevel.ALL voltmx.logger.logLevel.NONE voltmx.logger.logLevel.TRACE voltmx.logger.logLevel.DEBUG voltmx.logger.logLevel.INFO voltmx.logger.logLevel.WARN voltmx.logger.logLevel.ERROR voltmx.logger.logLevel.FATAL
Default Valuevoltmx.logger.logLevel.NONE
Read or WriteOnly Write
JavaScript Examplevar loggerConfig = new voltmx.logger.createLoggerConfig(); loggerConfig.logLevel = voltmx.logger.logLevel.INFO.value;

addPersistor

The property can be used to add file persistor through loggerConfig object.

SyntaxaddPersistor
Possible ValuesObject of type filePersistor
Default ValuesN/A
Read or WriteOnly Write
JavaScript Examplevar loggerConfig = new voltmx.logger.createLoggerConfig(); var filePers = new voltmx.logger.createFilePersistor();filePers.maxNumberOfLogFiles = 15; loggerConfig.addPersistor(filePers);

createNewLogger() API

SignaturecreateNewLogger
ParametersThis API takes three parameters: LoggerName, LoggerConfigloggerName: The loggerName is a string used to identify the instance of the loggerObject. Note: This is a mandatory value. loggerConfiguration: The loggerConfiguration is the configuration object. For more information, refer createLoggerConfig().
Return TypeReturns a logger object on which various functions such as trace(), debug(), info(), warn(), error() and fatal() APIs are exposed.
JavaScript Examplevar lConfig = new voltmx.logger.createLoggerConfig(); var loggerObj = new voltmx.logger.createNewLogger("AndroidLoggerDemo", lConfig);
Platform AvailabilityIDE, Android, iOS, and Windows 10

activatePersistors()

Unless we activate persistors, logs will not be pushed to the corresponding persistors. This is a mandatory step and no persistor is activated by default.

SignatureactivatePersistors
ParametersThe API takes one parameter: persistor name. This parameter could be either a console or a file.
Return TypeN/A
JavaScript Examplevoltmx.logger.activatePersistors(voltmx.logger.consolePersistor) voltmx.logger.activatePersistors(voltmx.logger.filePersistor) voltmx.logger.activatePersistors(voltmx.logger.consolePersistor | voltmx.logger.filePersistor)
Platform AvailabilityIDE, Android, iOS, and windows 10

Note: Console Persistor logs will not be available in Iris Windows 10 and Native Windows 10.

deactivatePersistors()

If you want to make sure the logs are not pushed to a corresponding persistor or any combination of them, use deactivatePersistors() API.

SignaturedeactivatePersistors
ParametersThe API takes one parameter: persistor name. This parameter could be either a console or a file or any combination of these.
Return TypeN/A
JavaScript Examplevoltmx.logger.deactivatePersistors(voltmx.logger.consolePersistor) voltmx.logger.deactivatePersistors(voltmx.logger.filePersistor) voltmx.logger.deactivatePersistors(voltmx.logger.consolePersistor | voltmx.logger.filePersistor)
Platform AvailabilityIDE, Android, iOS, and windows 10

trace() API