Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

Logs


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


_10
console.log("This is an info level log message from my function")
_10
_10
console.warn("This is a warning log message from my function")
_10
_10
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

serverless-toolkit-usage page anchor

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:


_10
twilio serverless:logs --tail


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


Stream live logs in the browser

stream-live-logs-in-the-browser page anchor

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.

(information)

Info

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

Limits and constraints

limits-and-constraints page anchor
  • 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.

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

NameType
StartDateISO 8601(optional)
EndDateISO 8601(optional)
FunctionSidsid<ZH> (optional)
PageTokenstring (optional)
PageSizeint (default: 50)

Resource properties
sidtype: SID<NO>Not PII

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


account_sidtype: SID<AC>Not PII

The SID of the Account(link takes you to an external page) that created the Log resource.


service_sidtype: SID<ZS>Not PII

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


environment_sidtype: SID<ZE>Not PII

The SID of the environment in which the log occurred.


build_sidtype: SID<ZB>Not PII

The SID of the build that corresponds to the log.


deployment_sidtype: SID<ZD>Not PII

The SID of the deployment that corresponds to the log.


function_sidtype: SID<ZH>Not PII

The SID of the function whose invocation produced the log.


request_sidtype: SID<RQ>Not PII

The SID of the request associated with the log.


leveltype: enum<STRING>Not PII

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

Possible values:
infowarnerror

messagetype: stringNot PII

The log message.


date_createdtype: string<DATE TIME>Not PII

The date and time in GMT when the Log resource was created specified in ISO 8601(link takes you to an external page) format.


urltype: string<URI>Not PII

The absolute URL of the Log resource.


GET https://serverless.twilio.com/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Logs/{Sid}

Parameters

fetch-parameters page anchor
URI parameters
ServiceSidtype: stringNot PII
Path Parameter

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


EnvironmentSidtype: SID<ZE>Not PII
Path Parameter

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


Sidtype: SID<NO>Not PII
Path Parameter

The SID of the Log resource to fetch.

Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_12
// Download the helper library from https://www.twilio.com/docs/node/install
_12
// Find your Account SID and Auth Token at twilio.com/console
_12
// and set the environment variables. See http://twil.io/secure
_12
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_12
const authToken = process.env.TWILIO_AUTH_TOKEN;
_12
const client = require('twilio')(accountSid, authToken);
_12
_12
client.serverless.v1.services('ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_12
.environments('ZEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_12
.logs('NOXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_12
.fetch()
_12
.then(log => console.log(log.sid));

Output

_14
{
_14
"sid": "NOXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_14
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_14
"service_sid": "ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_14
"environment_sid": "ZEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_14
"build_sid": "ZB00000000000000000000000000000000",
_14
"deployment_sid": "ZD00000000000000000000000000000000",
_14
"function_sid": "ZH00000000000000000000000000000000",
_14
"request_sid": "RQ00000000000000000000000000000000",
_14
"level": "warn",
_14
"message": "This is a warning",
_14
"date_created": "2018-11-10T20:00:00Z",
_14
"url": "https://serverless.twilio.com/v1/Services/ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Environments/ZE00000000000000000000000000000000/Logs/NO00000000000000000000000000000000"
_14
}


Read multiple Log resources

read-multiple-log-resources page anchor
GET https://serverless.twilio.com/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Logs

URI parameters
ServiceSidtype: stringNot PII
Path Parameter

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


EnvironmentSidtype: SID<ZE>Not PII
Path Parameter

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


FunctionSidtype: SID<ZH>Not PII
Query Parameter

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


StartDatetype: string<DATE TIME>Not PII
Query Parameter

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.


EndDatetype: string<DATE TIME>Not PII
Query Parameter

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


PageSizetype: integerNot PII
Query Parameter

How many resources to return in each list page. The default is 50, and the maximum is 1000.


Pagetype: integerNot PII
Query Parameter

The page index. This value is simply for client state.


PageTokentype: stringNot PII
Query Parameter

The page token. This is provided by the API.

Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_12
// Download the helper library from https://www.twilio.com/docs/node/install
_12
// Find your Account SID and Auth Token at twilio.com/console
_12
// and set the environment variables. See http://twil.io/secure
_12
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_12
const authToken = process.env.TWILIO_AUTH_TOKEN;
_12
const client = require('twilio')(accountSid, authToken);
_12
_12
client.serverless.v1.services('ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_12
.environments('ZEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_12
.logs
_12
.list({limit: 20})
_12
.then(logs => logs.forEach(l => console.log(l.sid)));

Output

_12
{
_12
"logs": [],
_12
"meta": {
_12
"first_page_url": "https://serverless.twilio.com/v1/Services/ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Environments/ZE00000000000000000000000000000000/Logs?StartDate=2018-11-10T20%3A00%3A00Z&EndDate=2018-12-10T20%3A00%3A00Z&FunctionSid=ZH00000000000000000000000000000000&PageSize=50&Page=0",
_12
"key": "logs",
_12
"next_page_url": "https://serverless.twilio.com/v1/Services/ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Environments/ZE00000000000000000000000000000000/Logs?StartDate=2018-11-10T20%3A00%3A00Z&EndDate=2018-12-10T20%3A00%3A00Z&FunctionSid=ZH00000000000000000000000000000000&PageSize=50&Page=1",
_12
"page": 0,
_12
"page_size": 50,
_12
"previous_page_url": "https://serverless.twilio.com/v1/Services/ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Environments/ZE00000000000000000000000000000000/Logs?StartDate=2018-11-10T20%3A00%3A00Z&EndDate=2018-12-10T20%3A00%3A00Z&FunctionSid=ZH00000000000000000000000000000000&PageSize=50&Page=0",
_12
"url": "https://serverless.twilio.com/v1/Services/ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Environments/ZE00000000000000000000000000000000/Logs?StartDate=2018-11-10T20%3A00%3A00Z&EndDate=2018-12-10T20%3A00%3A00Z&FunctionSid=ZH00000000000000000000000000000000&PageSize=50&Page=0"
_12
}
_12
}


Rate this page: