@@ -4,20 +4,49 @@ import {
44 FinalizeHandlerArguments ,
55 FinalizeHandlerOutput ,
66 FinalizeRequestHandlerOptions ,
7+ HandlerExecutionContext ,
78 MetadataBearer ,
89 Pluggable ,
910} from "@aws-sdk/types" ;
1011
1112import { LoggerResolvedConfig } from "./configurations" ;
1213
13- // eslint-disable-next-line @typescript-eslint/no-unused-vars
14- export const loggerMiddleware = ( options : LoggerResolvedConfig ) => < Output extends MetadataBearer = MetadataBearer > (
15- next : FinalizeHandler < any , Output >
14+ export const loggerMiddleware = ( ) => < Output extends MetadataBearer = MetadataBearer > (
15+ next : FinalizeHandler < any , Output > ,
16+ context : HandlerExecutionContext
1617) : FinalizeHandler < any , Output > => async (
1718 args : FinalizeHandlerArguments < any >
1819) : Promise < FinalizeHandlerOutput < Output > > => {
19- // TODO: use and call options.logger once it's available in context
20- return next ( args ) ;
20+ const { logger, inputFilterSensitiveLog, outputFilterSensitiveLog } = context ;
21+
22+ const response = await next ( args ) ;
23+
24+ if ( ! logger ) {
25+ return response ;
26+ }
27+
28+ const {
29+ output : { $metadata, ...outputWithoutMetadata } ,
30+ } = response ;
31+
32+ if ( typeof logger . debug === "function" ) {
33+ logger . debug ( {
34+ httpRequest : { ...( args . request as any ) , body : "examine input under info" } ,
35+ } ) ;
36+ logger . debug ( {
37+ httpResponse : { ...( response . response as any ) , body : "examine output under info" } ,
38+ } ) ;
39+ }
40+
41+ if ( typeof logger . info === "function" ) {
42+ logger . info ( {
43+ $metadata,
44+ input : inputFilterSensitiveLog ( args . input ) ,
45+ output : outputFilterSensitiveLog ( outputWithoutMetadata ) ,
46+ } ) ;
47+ }
48+
49+ return response ;
2150} ;
2251
2352export const loggerMiddlewareOptions : FinalizeRequestHandlerOptions & AbsoluteLocation = {
@@ -26,8 +55,9 @@ export const loggerMiddlewareOptions: FinalizeRequestHandlerOptions & AbsoluteLo
2655 step : "finalizeRequest" ,
2756} ;
2857
58+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2959export const getLoggerPlugin = ( options : LoggerResolvedConfig ) : Pluggable < any , any > => ( {
3060 applyToStack : ( clientStack ) => {
31- clientStack . add ( loggerMiddleware ( options ) , loggerMiddlewareOptions ) ;
61+ clientStack . add ( loggerMiddleware ( ) , loggerMiddlewareOptions ) ;
3262 } ,
3363} ) ;
0 commit comments