Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var AWS = require('aws-sdk');
- AWS.config.region = 'us-east-1'
- var service = new AWS.CloudWatchLogs();
- function getLogs(params) {
- params = Object.assign({}, params, { endTime: new Date().getTime() - 30000 })
- service.getLogEvents(p, function(err, data) {
- if (err) { console.log(err) }
- if (data && data.events && data.events.length !== 0) {
- data.events.forEach(function(event) {
- console.log(new Date(event.timestamp) + ' : ' + event.message)
- })
- }
- let nextParams = Object.assign({}, p, {
- startTime: undefined,
- nextToken: data.nextForwardToken
- })
- setTimeout(getLogs, 1000, nextParams)
- })
- }
- let logGroupName = process.argv[2]
- let logStreamName = process.argv[3]
- if (!logGroupName || !logStreamName) {
- return console.error('Usage: node cloudtail.js LogGroupName LogStreamName')
- }
- getLogs({
- logGroupName: logGroupName,
- logStreamName: logStreamName,
- startFromHead: false
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement