Menu

Expand
Rate this page:

Logs

The logs endpoint shows any debug logs produced by executed Functions. To have logs show up on this endpoint, add

console.log("This is an info level log message from my function")

console.warn("This is a warning log message from my function")

console.error("This is an error log message from my function")

to your Function code and invoke it. The log line will show up at the /Logs sub-resource of an Environment. Only Environments with a deployed build will generate logs.

Serverless toolkit usage

The Serverless Toolkit has debug log tail ability built in to aid in debugging from the command line. To tail logs for deployed functions, execute the following command from within a deployed Serverless project:

twilio serverless:logs --tail

Debugger and webhooks

Log lines written at WARN or ERROR level will also show up in the Twilio Debugger. Debugger will store WARN and ERROR logs for up to 30 days. You can setup a webhook to trigger on all (not just Functions) errors and warnings here.

Stream live logs in the browser

For Functions created via the API, you can show live logs for debugging by loading the Services page in the Twilio Console, opening the Service to track, and clicking the Show Logs toggle in the bottom-right corner of the UI.

The Show Logs toggle will only be visible if you have a live build associated with your environment via a Deployment.

Limits and constraints

  • Logs are available for the last 30 days only.
  • Logs are limited to the last 3KB of output per invocation. If you log over this limit, the output will be truncated.
  • Only 10,000 results are returned for a given query. Use the StartDate and EndDate filters to limit your query.
  • The /Logs endpoint is rate limited to 5 requests per second.
  • Timestamps for logs are to millisecond precision, which means that logs produced within the same millisecond could appear out of order.

Supported filters

Use these parameters on the /Logs request to retrieve specific logs.

Name

Type

StartDate

ISO 8601(optional)

EndDate

ISO 8601(optional)

FunctionSid

sid<ZH> (optional)

PageToken

string (optional)

PageSize

int (default: 50)

Log properties

Resource Properties in REST API format
sid
sid<NO> Not PII

The unique string that we created to identify the Log resource.

account_sid
sid<AC> Not PII

The SID of the Account that created the Log resource.

service_sid
sid<ZS> Not PII

The SID of the Service that the Log resource is associated with.

environment_sid
sid<ZE> Not PII

The SID of the environment in which the log occurred.

build_sid
sid<ZB> Not PII

The SID of the build that corresponds to the log.

deployment_sid
sid<ZD> Not PII

The SID of the deployment that corresponds to the log.

function_sid
sid<ZH> Not PII

The SID of the function whose invocation produced the log.

request_sid
sid<RQ> Not PII

The SID of the request associated with the log.

level
enum:level Not PII

The log level. Can be: info, warn, or error.

message
string Not PII

The log message.

date_created
date_time<iso8601> Not PII

The date and time in GMT when the Log resource was created specified in ISO 8601 format.

url
url Not PII

The absolute URL of the Log resource.

Fetch a Log resource

get
https://serverless.twilio.com/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Logs/{Sid}
Parameters
Parameters in REST API format
service_sid
Path
get sid_like<ZS> Not PII

The SID of the Service to fetch the Log resource from.

environment_sid
Path
get sid<ZE> Not PII

The SID of the environment with the Log resource to fetch.

sid
Path
get sid<NO> Not PII

The SID of the Log resource to fetch.

Example 1
Loading Code Sample...
        
        

        Fetch Log

        Read multiple Log resources

        get
        https://serverless.twilio.com/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Logs
        Parameters
        Parameters in REST API format
        service_sid
        Path
        get sid_like<ZS> Not PII

        The SID of the Service to read the Log resource from.

        environment_sid
        Path
        get sid<ZE> Not PII

        The SID of the environment with the Log resources to read.

        function_sid
        Optional
        get sid<ZH> Not PII

        The SID of the function whose invocation produced the Log resources to read.

        start_date
        Optional
        get date_time<iso8601> Not PII

        The date/time (in GMT, ISO 8601) after which the Log resources must have been created. Defaults to 1 day prior to current date/time.

        end_date
        Optional
        get date_time<iso8601> Not PII

        The date/time (in GMT, ISO 8601) before which the Log resources must have been created. Defaults to current date/time.

        Example 1
        Loading Code Sample...
              
              

              Read Log

              Rate this page:

              Need some help?

              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.

              Loading Code Sample...
                    
                    
                    

                    Thank you for your feedback!

                    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!

                    thanks-feedback-gif