Skip to content

Commit 231723b

Browse files
committed
chore: move logging of input/request to serde
1 parent fece417 commit 231723b

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

packages/middleware-logger/src/loggerMiddleware.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ export const loggerMiddleware = () => <Output extends MetadataBearer = MetadataB
2626
} = response;
2727

2828
if (typeof logger.debug === "function") {
29-
logger.debug({
30-
httpRequest: args.request,
31-
});
3229
logger.debug({
3330
httpResponse: response.response,
3431
});
@@ -37,7 +34,6 @@ export const loggerMiddleware = () => <Output extends MetadataBearer = MetadataB
3734
if (typeof logger.info === "function") {
3835
logger.info({
3936
$metadata,
40-
input: inputFilterSensitiveLog(args.input),
4137
output: outputFilterSensitiveLog(outputWithoutMetadata),
4238
});
4339
}
Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,40 @@
11
import {
22
EndpointBearer,
3+
HandlerExecutionContext,
34
RequestSerializer,
45
SerializeHandler,
56
SerializeHandlerArguments,
67
SerializeHandlerOutput,
78
SerializeMiddleware,
89
} from "@aws-sdk/types";
910

10-
export function serializerMiddleware<Input extends object, Output extends object, RuntimeUtils extends EndpointBearer>(
11+
export const serializerMiddleware = <Input extends object, Output extends object, RuntimeUtils extends EndpointBearer>(
1112
options: RuntimeUtils,
1213
serializer: RequestSerializer<any, RuntimeUtils>
13-
): SerializeMiddleware<Input, Output> {
14-
return (next: SerializeHandler<Input, Output>): SerializeHandler<Input, Output> => async (
15-
args: SerializeHandlerArguments<Input>
16-
): Promise<SerializeHandlerOutput<Output>> => {
17-
const request = await serializer(args.input, options);
18-
return next({
19-
...args,
20-
request,
14+
): SerializeMiddleware<Input, Output> => (
15+
next: SerializeHandler<Input, Output>,
16+
context: HandlerExecutionContext
17+
): SerializeHandler<Input, Output> => async (
18+
args: SerializeHandlerArguments<Input>
19+
): Promise<SerializeHandlerOutput<Output>> => {
20+
const { logger, inputFilterSensitiveLog } = context;
21+
22+
if (typeof logger?.info === "function") {
23+
logger.info({
24+
input: inputFilterSensitiveLog(args.input),
2125
});
22-
};
23-
}
26+
}
27+
28+
const request = await serializer(args.input, options);
29+
30+
if (typeof logger?.debug === "function") {
31+
logger.debug({
32+
httpRequest: request,
33+
});
34+
}
35+
36+
return next({
37+
...args,
38+
request,
39+
});
40+
};

0 commit comments

Comments
 (0)