# Debug your Function(s)

## Debug from the Console

If you're working on your Function in the Twilio Console, you can display live logs that can aid you in debugging your deployed Functions.

To start, toggle on **Live logs** in the Functions editor. As your Function is invoked, the log statements in your code are displayed in real time.

Given the following Function code, deployed with [Public Visibility](/docs/serverless/functions-assets/visibility):

```js
exports.handler = function(context, event, callback) {
  console.log("Invoked with: ", event);
  return callback(null, "OK");
};
```

If you invoke the Function with some arguments, their values are displayed in the Console.

```bash
curl https://your-domain-2242.twil.io/log-demo?key=value 
```

In this case, Twilio Functions streamed the start, end, and any `console` output of the Function into the Twilio console.

## Retrieve logs

If you leave your console session, the log messages that your Function(s) generated are still accessible as [Logs](/docs/serverless/api/resource/logs) through the Serverless API.

For example, if the example Function generated logs at different error levels (info, warn, and error). You can use the [Twilio CLI](/docs/twilio-cli) to retrieve these logs from the Serverless API:

```shell
twilio api:serverless:v1:services:environments:logs:list \
    --service-sid ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX \
    --environment-sid ZEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
```

The output may look like this:

```console
[ERROR][2021-10-27T22:07:54Z]: Invoked with:  { key: 'value' }
[WARNING][2021-10-27T22:07:54Z]: Invoked with:  { key: 'value' }
[INFO][2021-10-27T22:07:54Z]: Invoked with:  { key: 'value' }
```

For a less verbose command, install the [Serverless Toolkit](/docs/labs/serverless-toolkit) plugin for the CLI and issue the following command instead:

```shell
twilio serverless:logs \
    --service-sid=ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX \
    --environment=ZEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
```

Just as before, the output may look like this:

```console
[ERROR][2021-10-27T22:07:54Z]: Invoked with:  { key: 'value' }
[WARNING][2021-10-27T22:07:54Z]: Invoked with:  { key: 'value' }
[INFO][2021-10-27T22:07:54Z]: Invoked with:  { key: 'value' }
```

For more information about Logs, other ways to retrieve them, and their limitations, refer to the [Logs API Reference](/docs/serverless/api/resource/logs).

## Debug in real-time with Node.js

If you want to run your Function with a fully-featured debugger attached and have the ability to step through your code, use the [Serverless Toolkit](/docs/labs/serverless-toolkit).

[These setup instructions](/docs/labs/serverless-toolkit/developing#debugging-your-functions) allow you to run your Function on your local machine and step through its execution using any Node.js supported debugger, such as [Visual Studio Code](https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_attaching-to-nodejs) or the [Chrome Developer Tools](https://medium.com/the-node-js-collection/debugging-node-js-with-google-chrome-4965b5f910f4).

> \[!WARNING]
>
> You cannot use this method to debug Services that are created from the Console UI. Debugging in this manner is only possible if your project was initially created with the Serverless Toolkit.

## Monitor for errors and failures

If your Function returns an error, it is reported in the [Debugger](https://www.twilio.com/console/runtime/debugger).

> \[!NOTE]
>
> The Debugger supports search queries, as well as the option to group errors by their Function's URL or by error code.
