Skip to content

Commit c978f63

Browse files
AllanZhengYPsrchase
authored andcommitted
Logger & LoggerMiddleware (#66)
* add logger middleware and logger class * update logger level setting
1 parent bbcf1a8 commit c978f63

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

packages/types/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export * from './client';
33
export * from './credentials';
44
export * from './crypto';
55
export * from './http';
6+
export * from './logger';
67
export * from './marshaller';
78
export * from './middleware';
89
export * from './protocol';

packages/types/src/logger.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import {Shape, Member} from './protocol'
2+
3+
/**
4+
* A list of logger's log level. These levels are sorted in
5+
* order of increasing severity. Each log level includes itself and all
6+
* the levels behind itself.
7+
*
8+
* @example new Logger({logLevel: 'warn'}) will print all the warn and error
9+
* message.
10+
*/
11+
export type LogLevel = 'all' | 'log' | 'info' | 'warn' | 'error' | 'off'
12+
13+
/**
14+
* An object consumed by Logger constructor to initiate a logger object.
15+
*/
16+
export interface LoggerOptions {
17+
logger?: Logger;
18+
logLevel?: LogLevel;
19+
}
20+
21+
/**
22+
* Represents a logger object that is available in HandlerExecutionContext
23+
* throughout the middleware stack.
24+
*/
25+
export interface Logger {
26+
log(content: string): void;
27+
info(content: string): void;
28+
warn(content: string): void;
29+
error(content: string): void;
30+
}
31+
32+
/**
33+
* A function that removes the sensitive information from input parameters
34+
* and output objects being logged. Meanwhile this function will output
35+
* stringified object
36+
*
37+
* This function is mainly used in logging middleware.
38+
*/
39+
export interface SensitiveDataScrubber {
40+
(input: any, shape: Member): string
41+
}

packages/types/src/middleware.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
HttpRequest
55
} from './http';
66
import {OperationModel} from './protocol';
7+
import {Logger} from './logger'
78

89
export interface HandlerArguments<
910
InputType extends object,
@@ -165,7 +166,7 @@ export interface HandlerExecutionContext {
165166
/**
166167
* TODO Define a logger interface
167168
*/
168-
logger: any;
169+
logger: Logger;
169170

170171
/**
171172
* The serialization model for the input, output, and possible errors for

0 commit comments

Comments
 (0)