Skip to content

Commit

Permalink
Update debug-lib.js
Browse files Browse the repository at this point in the history
  • Loading branch information
jayair authored Aug 26, 2021
1 parent f64ad66 commit 1bc83be
Showing 1 changed file with 9 additions and 21 deletions.
30 changes: 9 additions & 21 deletions libs/debug-lib.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import AWS from "aws-sdk";
import util from "util";
import AWS from "aws-sdk";

let logs;

// Log AWS SDK calls
AWS.config.logger = { log: debug };

let logs;
let timeoutTimer;
export default function debug() {
logs.push({
date: new Date(),
string: util.format.apply(null, arguments),
});
}

export function init(event, context) {
logs = [];
Expand All @@ -16,27 +22,9 @@ export function init(event, context) {
pathParameters: event.pathParameters,
queryStringParameters: event.queryStringParameters,
});

// Start timeout timer
timeoutTimer = setTimeout(() => {
timeoutTimer && flush(new Error("Lambda will timeout in 100 ms"));
}, context.getRemainingTimeInMillis() - 100);
}

export function end() {
// Clear timeout timer
clearTimeout(timeoutTimer);
timeoutTimer = null;
}

export function flush(e) {
logs.forEach(({ date, string }) => console.debug(date, string));
console.error(e);
}

export default function debug() {
logs.push({
date: new Date(),
string: util.format.apply(null, arguments),
});
}

0 comments on commit 1bc83be

Please sign in to comment.