The logs endpoint shows any debug logs produced by executed Functions. To have logs show up on this endpoint, add
1console.log("This is an info level log message from my function")23console.warn("This is a warning log message from my function")45console.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.
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. 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.
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.
StartDate
and EndDate
filters to limit your query./Logs
endpoint is rate limited to 5 requests per second.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) |
The unique string that we created to identify the Log resource.
^NO[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The SID of the Account that created the Log resource.
^AC[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The SID of the Service that the Log resource is associated with.
^ZS[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The SID of the environment in which the log occurred.
^ZE[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The SID of the build that corresponds to the log.
^ZB[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The SID of the deployment that corresponds to the log.
^ZD[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The SID of the function whose invocation produced the log.
^ZH[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The SID of the request associated with the log.
^RQ[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The log level. Can be: info
, warn
, or error
.
info
warn
error
The date and time in GMT when the Log resource was created specified in ISO 8601 format.
The absolute URL of the Log resource.
GET https://serverless.twilio.com/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Logs/{Sid}
The SID of the environment with the Log resource to fetch.
^ZE[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The SID of the Log resource to fetch.
^NO[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function fetchLog() {11const log = await client.serverless.v112.services("ServiceSid")13.environments("ZEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")14.logs("NOaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")15.fetch();1617console.log(log.sid);18}1920fetchLog();
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}
GET https://serverless.twilio.com/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Logs
The SID of the function whose invocation produced the Log resources to read.
^ZH[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
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.
The date/time (in GMT, ISO 8601) before which the Log resources must have been created. Defaults to current date/time.
How many resources to return in each list page. The default is 50, and the maximum is 1000.
1
Maximum: 1000
The page token. This is provided by the API.
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function listLog() {11const logs = await client.serverless.v112.services("ServiceSid")13.environments("ZEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")14.logs.list({ limit: 20 });1516logs.forEach((l) => console.log(l.sid));17}1819listLog();
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}