0.2.1 • Published 4 years ago
@braintree/custom-actions-logger v0.2.1
@braintree/custom-actions-logger
Simple wrapper around @dazn/lambda-powertools-logger that provides a built-in tag parameter on all log messages. This logger outputs structured JSON logs. The logger also includes AWS Lambda environment information (awsRegion, functionName, functionVersion, functionMemorySize, and environment) and will capture all known correlation IDs within AWS Lambda.
Installation
$ npm add @braintree/custom-actions-loggerUsage
For Custom Action Handler Logging - Most Common
In this example, the context is passed to support logging correlation IDs
import { createLogger } from "@braintree/custom-actions-logger";
import type { Context } from "aws-sdk";
import {
BraintreeTransaction,
BraintreeTransactionStatus,
BraintreeEventHandlerResponse,
BraintreeBatchingStrategy,
} from "braintree-types";
export const MyHandler = async (
transaction: BraintreeTransaction,
context: Context
): Promise<BraintreeEventHandlerResponse> => {
const log = createLogger({ tag: "myTag", context });
log.info("A message", { key: "value" });
log.debug("A message", { key: "value" });
log.warn("A message", { key: "value" }, new Error("boom!"));
log.error("A message", { key: "value" }, new Error("boom!"));
// ...
};Generic Logging
import { createLogger } from "@braintree/custom-actions-logger";
const log = createLogger({ tag: "myTag" });
log.info("A message", { key: "value" });
log.debug("A message", { key: "value" });
log.warn("A message", { key: "value" }, new Error("boom!"));
log.error("A message", { key: "value" }, new Error("boom!"));