Logs
The logs endpoint shows any debug logs produced by executed Functions. To have logs show up on this endpoint, add
_10console.log("This is an info level log message from my function")
_10console.warn("This is a warning log message from my function")
_10console.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.
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.
Info
The Show Logs toggle will only be visible if you have a live build associated with your environment via a Deployment.
-
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.
Name | Type |
---|
StartDate | ISO 8601(optional) |
EndDate | ISO 8601(optional) |
FunctionSid | sid<ZH> (optional) |
PageToken | string (optional) |
PageSize | int (default: 50) |
Resource properties
sid
type: SID<NO>
The unique string that we created to identify the Log resource.
service_sid
type: SID<ZS>
The SID of the Service that the Log resource is associated with.
environment_sid
type: SID<ZE>
The SID of the environment in which the log occurred.
build_sid
type: SID<ZB>
The SID of the build that corresponds to the log.
deployment_sid
type: SID<ZD>
The SID of the deployment that corresponds to the log.
function_sid
type: SID<ZH>
The SID of the function whose invocation produced the log.
request_sid
type: SID<RQ>
The SID of the request associated with the log.
level
type: enum<string>
The log level. Can be: info
, warn
, or error
.
Possible values:
info
warn
error
date_created
type: string<date-time>
url
type: string<uri>
The absolute URL of the Log resource.
GET https://serverless.twilio.com/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Logs/{Sid}
URI parameters
ServiceSid
type: string
The SID of the Service to fetch the Log resource from.
EnvironmentSid
type: SID<ZE>
The SID of the environment with the Log resource to fetch.
Sid
type: SID<NO>
The SID of the Log resource to fetch.
_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
_12const accountSid = process.env.TWILIO_ACCOUNT_SID;
_12const authToken = process.env.TWILIO_AUTH_TOKEN;
_12const client = require('twilio')(accountSid, authToken);
_12client.serverless.v1.services('ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_12 .environments('ZEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_12 .logs('NOXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_12 .then(log => console.log(log.sid));
_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 "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"
GET https://serverless.twilio.com/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Logs
URI parameters
ServiceSid
type: string
The SID of the Service to read the Log resource from.
EnvironmentSid
type: SID<ZE>
The SID of the environment with the Log resources to read.
FunctionSid
type: SID<ZH>
The SID of the function whose invocation produced the Log resources to read.
StartDate
type: string<date-time>
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.
EndDate
type: string<date-time>
The date/time (in GMT, ISO 8601) before which the Log resources must have been created. Defaults to current date/time.
PageSize
type: integer
How many resources to return in each list page. The default is 50, and the maximum is 1000.
Page
type: integer
The page index. This value is simply for client state.
PageToken
type: string
The page token. This is provided by the API.
_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
_12const accountSid = process.env.TWILIO_ACCOUNT_SID;
_12const authToken = process.env.TWILIO_AUTH_TOKEN;
_12const client = require('twilio')(accountSid, authToken);
_12client.serverless.v1.services('ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_12 .environments('ZEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_12 .then(logs => logs.forEach(l => console.log(l.sid)));
_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 "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 "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"