@@ -4,20 +4,49 @@ import {
4
4
FinalizeHandlerArguments ,
5
5
FinalizeHandlerOutput ,
6
6
FinalizeRequestHandlerOptions ,
7
+ HandlerExecutionContext ,
7
8
MetadataBearer ,
8
9
Pluggable ,
9
10
} from "@aws-sdk/types" ;
10
11
11
12
import { LoggerResolvedConfig } from "./configurations" ;
12
13
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
16
17
) : FinalizeHandler < any , Output > => async (
17
18
args : FinalizeHandlerArguments < any >
18
19
) : 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 ;
21
50
} ;
22
51
23
52
export const loggerMiddlewareOptions : FinalizeRequestHandlerOptions & AbsoluteLocation = {
@@ -26,8 +55,9 @@ export const loggerMiddlewareOptions: FinalizeRequestHandlerOptions & AbsoluteLo
26
55
step : "finalizeRequest" ,
27
56
} ;
28
57
58
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
29
59
export const getLoggerPlugin = ( options : LoggerResolvedConfig ) : Pluggable < any , any > => ( {
30
60
applyToStack : ( clientStack ) => {
31
- clientStack . add ( loggerMiddleware ( options ) , loggerMiddlewareOptions ) ;
61
+ clientStack . add ( loggerMiddleware ( ) , loggerMiddlewareOptions ) ;
32
62
} ,
33
63
} ) ;
0 commit comments