Skip to content

feat(logs): add logs fetching and streaming #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Feb 21, 2020

Conversation

philnash
Copy link
Contributor

Initial attempt at turning polling for logs into a stream.

There are some bits missing, like passing through some of the filters in the LogsConfig. I can add them, I just wanted someone else to take a look at this and make sure I'm on the right track!

Basic usage

The following will initialise a serverless API client and get a stream of the logs. It will then log every time there are new logs returned from the stream.

const ServerlessAPI = require("@twilio-labs/serverless-api").default;
client = new ServerlessAPI({ accountSid: process.env.TWILIO_ACCOUNT_SID, authToken: process.env.TWILIO_AUTH_TOKEN});
let stream = await client.getLogsStream({ serviceSid: SERVICE_SID, environment: ENVIRONMENT_SID, tail: true })
stream.on('data', json => {
  const log = JSON.parse(json);
  console.log(`[${log.level}][${log.date_created}]: ${log.message}`);
});

Let me know what you think. Companion PR for twilio-run coming soon too.

Contributing to Twilio

All third-party contributors acknowledge that any contributions they provide will be made under the same open-source license that the open-source project is provided under.

  • I acknowledge that all my contributions will be made under the project's license.

Fixes reset-dependencies npm script and adds a watch script for continuous compilation.
Should pass a client to LogsStream instead of credentials, as that's how everything else works. Access through the client should set the client.

Also, changed how filtering old logs out on subsequent polls works to contain memory.
Adds StartDate, EndDate amd PageToken as options to listOnePageLogResources.
so that twilio-run can get a single page of recent logs
@philnash philnash requested a review from dkundel February 17, 2020 12:01
@dkundel dkundel changed the title Logs streams feat(logs): add logs fetching and streaming Feb 21, 2020
@dkundel dkundel merged commit f4f21b4 into twilio-labs:master Feb 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants