メニュー

Expand
ページを評価:

Functionのデバッグ

Debugging 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, then you will need to leverage the Serverless Toolkit.

These setup instructions will 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 or the Chrome Developer Tools.

Console上でのデバッグ

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

To start, click the Enable live logs button near the bottom-right of the Functions editor. As your Function is invoked, any log statements in your code will be displayed in real time.

Given the following Function code, deployed with Public Visibility:

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

If you invoke the Function with some arguments, you should see their values displayed in the console as shown below.

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

Function Live Logs

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

Retrieving logs

If you leave your console session by navigating away or closing the browser window, the log messages that your Function generate will still be accessible as Logs via the Serverless API.

For example, suppose the above Function also generated logs at different error levels (info, warn, and error), and we retrieved its logs via the Serverless Toolkit.

twilio serverless:logs \
    --service-sid=ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX \
    --environment=ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

The output may look like this:

[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, please refer to the Logs API Reference.

Monitoring for errors and failures

If your Function returns an error, it will be reported in the Debugger.

The Debugger supports search queries, as well as the option to group errors by their Function's URL or by error code.

ページを評価:

ヘルプが必要ですか?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd by visiting Twilio's Stack Overflow Collective or browsing the Twilio tag on Stack Overflow.

        
        
        

        フィードバックくださりありがとうございます!

        Please select the reason(s) for your feedback. The additional information you provide helps us improve our documentation:

        Sending your feedback...
        🎉 Thank you for your feedback!
        Something went wrong. Please try again.

        Thanks for your feedback!

        Refer us and get $10 in 3 simple steps!

        ステップ1

        Get link

        Get a free personal referral link here

        ステップ2:

        Give $10

        Your user signs up and upgrade using link

        ステップ3

        Get $10

        1,250 free SMSes
        OR 1,000 free voice mins
        OR 12,000 chats
        OR more