Pushing to Logs

You can push events and data to logs while writing a Catalyst function by including a statement in the function definition. This statement differs based on the function stack and the function type.

Catalyst enables you to write upto 1500 characters to the logs. You can therefore pass data in this range and include messages that require to be pushed.

You can also include the log level of a function statement to indicate its severity. The log levels are only relevant to Application logs and will not be displayed in Access logs. The log levels differ for Java, Node.js and Python functions. Refer to the Application Logs section to view the different log levelssupported by all platforms.

The methods to include in your function code to push the response data of each function stack and type are mentioned below:

Java Functions

You must include the following method in your function definition to push to logs for all function types:

    
copy
LOGGER.log()

You can include the log level for a Java function along with this statement. For example, to push a certain response obtained to the INFO level in a Java function, you can write:

    
copy
LOGGER.log(Level.INFO, "Hello "+name);

Alternatively you can also use logger.severe(), logger.warning() or logger.info() for all function types.

Node.js Functions

The Basic I/O functions support a different method to write data to Logs from the other function types in the Node.js platform.

You must include the following method in your function definition to push to logs in a Basic I/O function:

    
copy
context.log()

For example, to push a certain response obtained to logs, you can write:

    
copy
context.log("Value : " + result);

Similar to Java functions, you can include the log level supported by Node.js functions along with this statement.

For functions of the other types (Advanced I/O, Cron, Event, Integration and Browser Logic functions), you must include the method below in your function definition to push to logs. This method applies to Basic I/O function as well.

    
copy
console.log()

This is a native Node.js method to write to logs that is supported by Catalyst. The following example contains a push to logs statement of the ERROR log level in a catch block:

    
copy
catch (err) { console.error(err); res.status(500).send({ message: 'Internal Server Error. Please try again after sometime.', error: err }) }

Similarly, you can also other direct methods like console.warning(), console.info() or console.debug() to push the logs for all function types.

Python Functions

The Basic I/O functions support a different method to write data to Logs from the other function types in the Python platform.

You must include the following method in your function definition to push to logs in a Basic I/O function:

    
copy
context.log()

Similar to Node.js functions, you can write relevant informative messages and push them as a response to the logs.

For functions of the other types (Advanced I/O, Cron, Event, Integration and Browser Logic functions), you must include the method below in your function definition to push to logs:

    
copy
LOGGER.log(Level.INFO, "Hello "+name);

Alternatively you can also use direct methods like logger.critical(), logger.warning(), logger.error(), logger.info() or logger.debug() for all function types.

Note: Refer to the Application Logs section to view the log levels supported by Java, Node.js and Python functions.

Last Updated 2023-09-05 15:16:18 +0530 +0530

ON THIS PAGE