Skip to content

Commit

Permalink
Logger & LoggerMiddleware (#66)
Browse files Browse the repository at this point in the history
* add logger middleware and logger class

* update logger level setting
  • Loading branch information
AllanZhengYP authored and srchase committed Mar 23, 2023
1 parent bbcf1a8 commit c978f63
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export * from './client';
export * from './credentials';
export * from './crypto';
export * from './http';
export * from './logger';
export * from './marshaller';
export * from './middleware';
export * from './protocol';
Expand Down
41 changes: 41 additions & 0 deletions packages/types/src/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import {Shape, Member} from './protocol'

/**
* A list of logger's log level. These levels are sorted in
* order of increasing severity. Each log level includes itself and all
* the levels behind itself.
*
* @example new Logger({logLevel: 'warn'}) will print all the warn and error
* message.
*/
export type LogLevel = 'all' | 'log' | 'info' | 'warn' | 'error' | 'off'

/**
* An object consumed by Logger constructor to initiate a logger object.
*/
export interface LoggerOptions {
logger?: Logger;
logLevel?: LogLevel;
}

/**
* Represents a logger object that is available in HandlerExecutionContext
* throughout the middleware stack.
*/
export interface Logger {
log(content: string): void;
info(content: string): void;
warn(content: string): void;
error(content: string): void;
}

/**
* A function that removes the sensitive information from input parameters
* and output objects being logged. Meanwhile this function will output
* stringified object
*
* This function is mainly used in logging middleware.
*/
export interface SensitiveDataScrubber {
(input: any, shape: Member): string
}
3 changes: 2 additions & 1 deletion packages/types/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
HttpRequest
} from './http';
import {OperationModel} from './protocol';
import {Logger} from './logger'

export interface HandlerArguments<
InputType extends object,
Expand Down Expand Up @@ -165,7 +166,7 @@ export interface HandlerExecutionContext {
/**
* TODO Define a logger interface
*/
logger: any;
logger: Logger;

/**
* The serialization model for the input, output, and possible errors for
Expand Down

0 comments on commit c978f63

Please sign in to comment.