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 error level of a certain statement to indicate its severity. The log levels are only relevant to Application logs and are will not be displayed in Access logs. The log levels differ for Java and Node.js functions. Refer to the Application Logs section to view the different log levels supported by both 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);

Refer to the Application Logs section to view the log levels supported by Java functions.

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. Refer to the Application Logs section to view the log levels supported by Node.js functions.

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

    
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.log(err); res.status(500).send({ message: 'Internal Server Error. Please try again after sometime.', error: err }) }

ON THIS PAGE