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
andEndDate
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 |
|
ISO 8601(optional) |
|
ISO 8601(optional) |
|
sid<ZH> (optional) |
|
string (optional) |
|
int (default: 50) |
Log properties
Resource Properties in REST API format | |
---|---|
sid
|
The unique string that we created to identify the Log resource. |
account_sid
|
The SID of the Account that created the Log resource. |
service_sid
|
The SID of the Service that the Log resource is associated with. |
environment_sid
|
The SID of the environment in which the log occurred. |
build_sid
|
The SID of the build that corresponds to the log. |
deployment_sid
|
The SID of the deployment that corresponds to the log. |
function_sid
|
The SID of the function whose invocation produced the log. |
request_sid
|
The SID of the request associated with the log. |
level
|
The log level. Can be: |
message
|
The log message. |
date_created
|
The date and time in GMT when the Log resource was created specified in ISO 8601 format. |
url
|
The absolute URL of the Log resource. |
Fetch a Log resource
https://serverless.twilio.com/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Logs/{Sid}
Parameters
Parameters in REST API format | |
---|---|
service_sid
Path
|
The SID of the Service to fetch the Log resource from. |
environment_sid
Path
|
The SID of the environment with the Log resource to fetch. |
sid
Path
|
The SID of the Log resource to fetch. |
Example 1
Read multiple Log resources
https://serverless.twilio.com/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Logs
Parameters
Parameters in REST API format | |
---|---|
service_sid
Path
|
The SID of the Service to read the Log resource from. |
environment_sid
Path
|
The SID of the environment with the Log resources to read. |
function_sid
Optional
|
The SID of the function whose invocation produced the Log resources to read. |
start_date
Optional
|
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
|
The date/time (in GMT, ISO 8601) before which the Log resources must have been created. Defaults to current date/time. |
Example 1
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.