Skip to contentSkip to navigationSkip to topbar
On this page

Logs


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

1
console.log("This is an info level log message from my function")
2
3
console.warn("This is a warning log message from my function")
4
5
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:

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)

Property nameTypeRequiredDescriptionChild properties
sidSID<NO>Optional
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>Optional

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>Optional

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>Optional

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>Optional

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>Optional

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>Optional

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>Optional

The SID of the request associated with the log.

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

levelenum<string>Optional

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

Possible values:
infowarnerror

messagestringOptional

The log message.


date_createdstring<date-time>Optional

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


urlstring<uri>Optional

The absolute URL of the Log resource.


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

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 LogLink to code sample: Fetch a Log
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function fetchLog() {
11
const log = await client.serverless.v1
12
.services("ServiceSid")
13
.environments("ZEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
14
.logs("NOaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
15
.fetch();
16
17
console.log(log.sid);
18
}
19
20
fetchLog();

Output

1
{
2
"sid": "NOaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
4
"service_sid": "ServiceSid",
5
"environment_sid": "ZEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
6
"build_sid": "ZB00000000000000000000000000000000",
7
"deployment_sid": "ZD00000000000000000000000000000000",
8
"function_sid": "ZH00000000000000000000000000000000",
9
"request_sid": "RQ00000000000000000000000000000000",
10
"level": "warn",
11
"message": "This is a warning",
12
"date_created": "2018-11-10T20:00:00Z",
13
"url": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/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

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

1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function listLog() {
11
const logs = await client.serverless.v1
12
.services("ServiceSid")
13
.environments("ZEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
14
.logs.list({ limit: 20 });
15
16
logs.forEach((l) => console.log(l.sid));
17
}
18
19
listLog();

Output

1
{
2
"logs": [],
3
"meta": {
4
"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",
5
"key": "logs",
6
"next_page_url": null,
7
"page": 0,
8
"page_size": 50,
9
"previous_page_url": null,
10
"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"
11
}
12
}

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.