CMSgov/macpro-platform-doc-conversion

View on GitHub
services/app-api/libs/debug-lib.js

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
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);
}