services/app-api/libs/debug-lib.js
import util from "util";
import AWS from "aws-sdk";
import * as debugLib from "./debug-lib";
let logs;
// Log AWS SDK calls
AWS.config.logger = { log: debug };
export function debug() {
logs.push({
date: new Date(),
string: util.format.apply(null, arguments),
});
}
export function init(event, context) {
logs = [];
// Log API event
debugLib.debug("API event", {
body: event.body,
pathParameters: event.pathParameters,
queryStringParameters: event.queryStringParameters,
});
}
export function flush(e) {
logs.forEach(({ date, string }) => console.debug(date, string));
console.error(e);
}