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.
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().
- 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 to0xa. For example, when x is 10, the message ID in the log is0x085a0000a. 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 ID0x085a00001and 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
categorykeyword 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
myCategorycategory at the defaultinfolevel.console.options({'category':'myCategory'}).log('text'); - Log to the
myCategorycategory at theerrorlevel.console.options({'category':'myCategory'}).error('text'); - Use the returned object to log an error message directly to the
slmcategory.var logSLM = console.options({'category':'slm'}); logSLM.error('My message text.');
- Log to the
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.