Releases And Snippets

Debugging your Function Stacks with Debug Log

Summary

Debugging can be a challenging task, especially when dealing with complex function stacks or large datasets. Xano's new "Debug Log" feature aims to simplify the troubleshooting process by providing a convenient way to output specific data or messages to a dedicated log while using "Run and Debug."

What is Debug Log?

Similar to JavaScript's `console.log` command, Debug Log allows you to output specific data or messages to a debug log within Xano. This can be incredibly helpful for diagnosing issues within your function stack, especially when dealing with large datasets or complex operations.

How to Use Debug Log

Using Debug Log is straightforward. Here's a step-by-step guide:

  1. Open Your Function Stack: Navigate to the function stack where you want to incorporate Debug Log.
  2. Add the "Debug Log" Step: Under the "Utility Functions" section, locate and add the "Debug Log" step to your function stack.
  3. Select the Value to Log: Choose the variable or data you want to output to the debug log. You can also apply filters if needed.
  4. Run and Debug: Execute your function stack using the "Run and Debug" feature.
  5. View the Debug Log: After running your function stack, a new tab labeled "Debug Logs" will appear. Click on this tab to view the outputted data or messages.

It's that simple! The Debug Log will display the contents of the variables or data you specified in the order they were logged during the execution of your function stack.

A Practical Example

Let's explore a practical example to better understand how Debug Log can help streamline your troubleshooting process.

Imagine you have a function stack that queries a large table (with around 1,500 records) and then uses a `forEach` loop to update a specific value within each record. In this case, you're applying a simple text transformation to one of the fields, converting all letters to uppercase.

During execution, you encounter an error: `argument one must be of type string null given`. This likely means that at some point, a record with a null value is being passed to the filter, which doesn't work because you cannot apply text transformations to null values.

Typically, you would use the debugger to identify the problematic record. However, if your table has over 400,000 entries, finding and fixing the issue could be challenging, especially if there are multiple problematic records.

Here's where Debug Log shines:

  1. Add a Debug Log Step: In your function stack, add a new "Debug Log" step, and specify the value to log as `item.id`. This will log the ID of each record being processed in the loop.
  2. Run and Debug: Execute your function stack using "Run and Debug."
  3. Identify the Problematic Record(s): After execution, navigate to the "Debug Logs" tab. Unlike the debugger, which is limited to showing details on the first 1,000 entries, the Debug Log can display all logged items without limitations (based on your machine's memory).
  4. Optimize with Conditionals: To further improve efficiency, you can add a conditional step to only log the IDs of records with null values. This way, you can quickly identify and fix the problematic records without sifting through thousands of log entries.

By leveraging Debug Log, you can easily track and identify the specific records causing issues, streamlining the troubleshooting process and saving valuable time.

Key Benefits of Debug Log

  • Targeted Logging: Debug Log allows you to output specific data or messages, providing granular control over what information is logged.
  • Seamless Integration: Debug Log seamlessly integrates with Xano's "Run and Debug" feature, making it easy to incorporate into your existing workflow.
  • No External Impact: Debug Log steps only execute when using "Run and Debug" and do not impact external calls to your APIs, ensuring minimal disruption to your production environment.
  • Improved Debugging Experience: With Debug Log, you can quickly identify and resolve issues, especially when dealing with large datasets or complex operations.

Whether you're a no-code enthusiast, a citizen developer, a traditional developer, or part of a startup or small business, Debug Log can significantly enhance your debugging experience within the Xano platform.

Give Debug Log a try and experience the power of streamlined troubleshooting in Xano. Happy coding!

This transcript was AI generated to allow users to quickly answer technical questions about Xano.

Was this helpful?

I found it helpful

I need more support
Sign up for XanoSign up for Xano

Build without limits on a secure, scalable backend.

Unblock your team's progress and create a backend that will scale for free.

Start building for free