Skip to content

Commit

Permalink
chore: add loggerMiddleware initial setup
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr committed Aug 26, 2020
1 parent 450e3fb commit 393d504
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/middleware-logger/src/configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ export interface LoggerInputConfig {
logger?: Logger;
}

interface PreviouslyResolved {}

export interface LoggerResolvedConfig {
logger?: Logger;
}

export const resolveLoggerConfig = <T>(input: T & PreviouslyResolved & LoggerInputConfig): T & LoggerResolvedConfig =>
input;
1 change: 1 addition & 0 deletions packages/middleware-logger/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./configurations";
export * from "./loggerMiddleware";
33 changes: 33 additions & 0 deletions packages/middleware-logger/src/loggerMiddleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {
AbsoluteLocation,
FinalizeHandler,
FinalizeHandlerArguments,
FinalizeHandlerOutput,
FinalizeRequestHandlerOptions,
MetadataBearer,
Pluggable,
} from "@aws-sdk/types";

import { LoggerResolvedConfig } from "./configurations";

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export const loggerMiddleware = (options: LoggerResolvedConfig) => <Output extends MetadataBearer = MetadataBearer>(
next: FinalizeHandler<any, Output>
): FinalizeHandler<any, Output> => async (
args: FinalizeHandlerArguments<any>
): Promise<FinalizeHandlerOutput<Output>> => {
// TODO: use and call options.logger once it's available in context
return next(args);
};

export const loggerMiddlewareOptions: FinalizeRequestHandlerOptions & AbsoluteLocation = {
name: "loggerMiddleware",
tags: ["LOGGER"],
step: "finalizeRequest",
};

export const getLoggerPlugin = (options: LoggerResolvedConfig): Pluggable<any, any> => ({
applyToStack: (clientStack) => {
clientStack.add(loggerMiddleware(options), loggerMiddlewareOptions);
},
});

0 comments on commit 393d504

Please sign in to comment.