Skip to main content

log

This function prints a message to the server log console. It is used for debugging.

The function is supported in all runtimes:

  • ECMAScript 5.
  • ECMAScript 6, in synchronous and asynchronous functions.

Arguments​

The log function can take arguments of any type.

tip
If a json object is passed to it, it will be printed to the log console in its entirety, with every field printed out.

How to use​

For example, the log function can be used to track current values of variables and object attributes:

state: Start
q!: $regex</start>
script:
$session.codes = ["AAAA","BBBB","CCCC"];

state: GetPromoCode
q!: want * get * promo code
a: Your promo code is {{ $session.codes.shift() }}
script:
log("Promo codes left: " + $session.codes.length);

Then the expected log console output will be:

2025-04-23T12:08:42.095Z
Promo codes left: 2
info

By default, messages have the Info logging level.

Log levels in ECMAScript 6​

In ECMAScript 6 you can also set the level of a message: info, debug, warn, or error. To do this, call the log.<level> function, where <level> is the logging level.

Examples:

log.info("Promo code request: EXAMPLE");
log.debug("User successfully received promo code: EXAMPLE");
log.warn("User has no promo codes available");
log.error("Error loading promo codes from the server");

Display settings affect which of these messages are shown in the server logs.