console module

Use the methods in the console module to write a log message to the DataPower® system log.

The console module is provided without having to use the require('console') statement. This module is automatically attached to the Global object.

The methods in this module can take multiple arguments with a printf style format specifier. If formatting elements are not found in the first string, each argument is inspected and converted to a string representation.
You can use the format specifiers to specify information in any of the console methods. These specifiers are similar to the C language printf function and are used in the same ways. For example, console.error('%2$d and %1$s', 'string', 10). The number that follows the % character indicates the position of the specification in the string.
%b
Binary
%c
Character
%d
%i
Signed decimal integer.
%e
Scientific notation (mantissa and exponent), lowercase.
%E
Scientific notation (mantissa and exponent), uppercase.
%f
Decimal floating point.
%o.
Unsigned octal.
%O.
Converted object from util.inspect().
%s
String of characters from toString().
%S
String of characters, uppercase.
%u
Unsigned decimal integer.
%x
Unsigned hex integer, lowercase.
%X
Unsigned hex integer, uppercase.
%j
JSON string from JSON.stringify().
User-defined message IDs:
  • You can write user-defined messages to the system log. You can create GatewayScript or policy rules that use user-defined messages. You can configure log events to trigger CLI commands that are based on the message IDs.
  • You specify a special message ID by using a predefined variable console.ID.DPUSR_MSGx, where x is a decimal value in the range 1 - 10. In the log, resulting message IDs are hex values up to 0xa. For example, when x is 10, the message ID in the log is 0x085a0000a. The message IDs cannot be specified directly in either string or integer format.
  • For example, console.error(console.ID.DPUSR_MSG1, "This is a user defined message") puts the predefined message ID 0x085a00001 and the message text into the system log at the error level.

console.alert()

Writes messages to the system log at the alert level.

Syntax
console.alert([data][,list])
Parameters
data
The format string is composed of zero or more directives.
list
The argument list to produce the output based on the format string.

console.critical()

Writes messages to the system log at the critical level.

Syntax
console.critical([data][,list])
Parameters
data
The format string is composed of zero or more directives.
list
The argument list to produce the output based on the format string.

console.debug()

Writes messages to the system log at the critical level.

Syntax
console.debug([data][,list])
Parameters
data
The format string is composed of zero or more directives.
list
The argument list to produce the output based on the format string.

console.emerg()

Writes messages to the system log at the emergency level.

Syntax
console.emerg([data][,list])
Parameters
data
The format string is composed of zero or more directives.
list
The argument list to produce the output based on the format string.

console.error()

Writes messages to the system log at the error level.

Syntax
console.error([data][,list])
Parameters
data
The format string is composed of zero or more directives.
list
The argument list to produce the output based on the format string.

console.info()

Writes messages to the system log at the informational level.

Syntax
console.info([data][,list])
Parameters
data
The format string is composed of zero or more directives.
list
The argument list to produce the output based on the format string.

console.log()

Writes messages to the system log at the informational level.

Syntax
console.log([data][,list])
Parameters
data
The format string is composed of zero or more directives.
list
The argument list to produce the output based on the format string.

console.notice()

Writes messages to the system log at the notice level.

Syntax
console.notice([data][,list])
Parameters
data
The format string is composed of zero or more directives.
list
The argument list to produce the output based on the format string.

console.options()

Specifies the log category to use during logging.

Syntax
console.options({'category':'label'}).level('message');
Parameters
label
The string that identifies the log category.
level
The keyword that identifies the log level for the message.
message
The string that defines the message to log.
Guidelines
The console.options() method takes a JSON object with the category keyword and the wanted log category. For performance reasons, this method returns a dummy object that has console object methods. This method supports chaining.

You can use this method instead of a level-specific method for flexibility.

Examples
  • Log to the myCategory category at the default info level.
    console.options({'category':'myCategory'}).log('text');
  • Log to the myCategory category at the error level.
    console.options({'category':'myCategory'}).error('text');
  • Use the returned object to log an error message directly to the slm category.
    var logSLM = console.options({'category':'slm'});
    logSLM.error('My message text.');

console.trace()

Writes messages to the system log at the trace level.

Syntax
console.trace([data][,list])
Parameters
data
The format string is composed of zero or more directives.
list
The argument list to produce the output based on the format string.

console.warn()

Writes messages to the system log at the warning level.

Syntax
console.warn([data][,list])
Parameters
data
The format string is composed of zero or more directives.
list
The argument list to produce the output based on the format string.