Home>Catalyst 101>Logs and debugging for better app performance

Logs and debugging for better app performance

catalyst usecase author
Srilakshmi | Technical writer

Inside the Cookbook

    • Logs: How do they work in Catalyst?
      • Types of logs in Catalyst
        • Logging and debugging in Catalyst
          • Java functions
          • Node.js functions
          • Python functions
        • Log levels and severity
          • Using logs for debugging
            • Catalyst log filters
              • Application performance monitoring (APM)
            • Conclusion

              Catalyst is a full stack cloud platform that allows developers to build, deploy, and manage scalable applications effortlessly. With a host of built-in services such as serverless functions, job scheduling, and object storage, Catalyst simplifies the development process. However, as any developer knows, building an application is only part of the journey; monitoring and debugging it are equally important.

              This blog will delve into Catalyst Logs that help you track and debug your application.

              Logs: How do they work in Catalyst?

              • Catalyst Logs is a component of DevOps that provides logs of all function executions.
              • It allows you to view both successful and failed executions, including internal executions triggered by the system.
              • These logs give you access to vital information, such as error messages, execution times, and parameters, helping you identify bugs in your code.
              • Whether you are in the Development or Production environment, logs are crucial for monitoring application behavior.
              • Catalyst retains logs for 7 days in the Development environment and 14 days in the Production environment, giving you sufficient time to debug issues.

              Types of logs in Catalyst

              Catalyst logs are categorized into two primary types:

              1. Access logs
                Access logs capture the external access layer of a function’s execution. This applies primarily to functions invoked manually by users, such as Basic I/O, Advanced I/O, Integration, and Browser Logic functions.

              2. Application logs
                Application logs provide details about the internal application layer of a function’s execution. These logs are relevant for both functions invoked by the user and those triggered internally by the system. This log type applies to all function types in Catalyst, including Event and job functions.

              Logging and debugging in Catalyst

              Logging helps developers track the execution flow and catch errors during development. Catalyst provides various ways to log events and messages while writing a function. Below is a breakdown of how logging works in different programming stacks.

              Java functions

              
              
              //To push data to logs in a Java function, use the following statement:
              LOGGER.log(Level.INFO, "Hello " + name);
              //Alternatively, you can use methods like logger.severe(), logger.warning(), or logger.info() to log events at different levels of severity.
                

               

              Node.js functions

              For Basic I/O functions in Node.js, use:

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

               

              For other function types (Advanced I/O, job, Event, etc.), you can use:

              console.log("Value: " + result);
                

               

              This method allows you to log messages at different levels, such as console.error(), console.warn(), or console.info().

              Python functions

              For Basic I/O functions in Python, use:

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

              For other function types, the logging mechanism is the same as Java, using LOGGER.log() or methods like logger.info(), logger.error(), and logger.warning().

              Log levels and severity

              Logs can be filtered by log levels that indicate the severity of an event.

              • Java: Severe, Warning, Info

              • Node.js: Error, Info, Warning, Debug

              • Python: Critical, Error, Warning, Info, Debug

              These log levels help you categorize your logs based on their importance and severity. For example, if something goes wrong, you would log it with a level like Error or Severe, while a successful execution would be logged as Info.

              Using logs for debugging

              Logging is an essential tool for debugging. With Catalyst, you can easily track issues, view error messages, and pinpoint where things went wrong. For instance, if you encounter an error in your Cron job, Catalyst will display it in the logs along with the execution history, allowing you to take immediate action.

              Example: Logging in Node.js 

              Here’s how you can use logs in a Node.js function:

              
              exports = async function(context) {
                try {
                  const result = await fetchDataFromAPI();
                  context.log("Data fetched successfully:", result);
                } catch (err) {
                  context.log("Error occurred:", err.message);
                  throw err; // re-throw the error for Catalyst to capture in the logs
                }
              };
              
              
               

               

              In this example, if the function succeeds, it logs the fetched data. If there is an error, it logs the error message and throws it to ensure it is captured in the Catalyst logs.

              Catalyst log filters

              You can filter logs to narrow down your search and focus on specific events. Here are some filters you can use.

              • Log Type: Choose between Application or Access logs.

              • Log Level: Filter by severity (e.g., Info, Error, Debug).

              • Function Name: Filter logs by specific functions.

              • Execution ID: Useful for filtering logs of job or Event functions.

              These filters allow you to find the relevant log entries quickly and take action based on the log level or specific execution.

              Application performance monitoring (APM)

              While Catalyst logs provide basic information about function executions, application performance monitoring (APM) offers in-depth insights into your application’s performance. APM can help you track response times, monitor errors, and measure the efficiency of each function. You can enable APM for better visibility into your app’s performance.

              Conclusion

              Catalyst reduces the burden of developers by providing built-in, centralized logging for all function executions, eliminating the need to set up and manage separate logging systems. It offers easy access to detailed logs for quick debugging and automatically handles log retention and security. Catalyst's ability to retain logs for extended periods, coupled with its log-level filters, helps developers troubleshoot problems easily. Furthermore, APM enhances the logs by providing detailed insights into performance metrics, enabling a more thorough analysis.

              By understanding and utilizing Catalyst’s logging capabilities, you can optimize your applications and quickly resolve issues during the development process.

              Explore the Catalyst Console and learn how to set up application performance monitoring.