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

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


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 set up 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.

(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

  • 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.

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

Log Properties

Property nameTypePIIDescription
sidSID<NO>
Not PII

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

Pattern: ^NO[0-9a-fA-F]{32}$Min length: 34Max length: 34

account_sidSID<AC>

The SID of the Account that created the Log resource.

Pattern: ^AC[0-9a-fA-F]{32}$Min length: 34Max length: 34

service_sidSID<ZS>

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

Pattern: ^ZS[0-9a-fA-F]{32}$Min length: 34Max length: 34

environment_sidSID<ZE>

The SID of the environment in which the log occurred.

Pattern: ^ZE[0-9a-fA-F]{32}$Min length: 34Max length: 34

build_sidSID<ZB>

The SID of the build that corresponds to the log.

Pattern: ^ZB[0-9a-fA-F]{32}$Min length: 34Max length: 34

deployment_sidSID<ZD>

The SID of the deployment that corresponds to the log.

Pattern: ^ZD[0-9a-fA-F]{32}$Min length: 34Max length: 34

function_sidSID<ZH>

The SID of the function whose invocation produced the log.

Pattern: ^ZH[0-9a-fA-F]{32}$Min length: 34Max length: 34

request_sidSID<RQ>

The SID of the request associated with the log.

Pattern: ^RQ[0-9a-fA-F]{32}$Min length: 34Max length: 34

levelenum<string>

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

Possible values:
infowarnerror

messagestring

The log message.


date_createdstring<date-time>

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


urlstring<uri>

The absolute URL of the Log resource.


Fetch a Log resource

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

Path parameters

Property nameTypeRequiredPIIDescription
ServiceSidstringrequired

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


EnvironmentSidSID<ZE>required

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

Pattern: ^ZE[0-9a-fA-F]{32}$Min length: 34Max length: 34

SidSID<NO>required

The SID of the Log resource to fetch.

Pattern: ^NO[0-9a-fA-F]{32}$Min length: 34Max length: 34

Fetch a Log

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

_20
// Download the helper library from https://www.twilio.com/docs/node/install
_20
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_20
_20
// Find your Account SID and Auth Token at twilio.com/console
_20
// and set the environment variables. See http://twil.io/secure
_20
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_20
const authToken = process.env.TWILIO_AUTH_TOKEN;
_20
const client = twilio(accountSid, authToken);
_20
_20
async function fetchLog() {
_20
const log = await client.serverless.v1
_20
.services("ServiceSid")
_20
.environments("ZEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_20
.logs("NOaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_20
.fetch();
_20
_20
console.log(log.sid);
_20
}
_20
_20
fetchLog();

Output

_14
{
_14
"sid": "NOaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_14
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_14
"service_sid": "ServiceSid",
_14
"environment_sid": "ZEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_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/ZS00000000000000000000000000000000/Environments/ZE00000000000000000000000000000000/Logs/NO00000000000000000000000000000000"
_14
}


Read multiple Log resources

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

Path parameters

Property nameTypeRequiredPIIDescription
ServiceSidstringrequired

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


EnvironmentSidSID<ZE>required

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

Pattern: ^ZE[0-9a-fA-F]{32}$Min length: 34Max length: 34

Query parameters

Property nameTypeRequiredPIIDescription
FunctionSidSID<ZH>Optional

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

Pattern: ^ZH[0-9a-fA-F]{32}$Min length: 34Max length: 34

StartDatestring<date-time>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.


EndDatestring<date-time>Optional

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


PageSizeintegerOptional

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

Minimum: 1Maximum: 1000

PageintegerOptional

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

Minimum: 0

PageTokenstringOptional

The page token. This is provided by the API.

List multiple Logs

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

_19
// Download the helper library from https://www.twilio.com/docs/node/install
_19
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_19
_19
// Find your Account SID and Auth Token at twilio.com/console
_19
// and set the environment variables. See http://twil.io/secure
_19
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_19
const authToken = process.env.TWILIO_AUTH_TOKEN;
_19
const client = twilio(accountSid, authToken);
_19
_19
async function listLog() {
_19
const logs = await client.serverless.v1
_19
.services("ServiceSid")
_19
.environments("ZEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_19
.logs.list({ limit: 20 });
_19
_19
logs.forEach((l) => console.log(l.sid));
_19
}
_19
_19
listLog();

Output

_12
{
_12
"logs": [],
_12
"meta": {
_12
"first_page_url": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/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": null,
_12
"page": 0,
_12
"page_size": 50,
_12
"previous_page_url": null,
_12
"url": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/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: