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:
copyLOGGER.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:
copyLOGGER.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:
copycontext.log()
For example, to push a certain response obtained to logs, you can write:
copycontext.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.
copyconsole.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:
copycatch (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:
copycontext.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:
copyLOGGER.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.
Last Updated 2023-09-05 15:16:18 +0530 +0530
Yes
No
Send your feedback to us