Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Add logger builder #65

Merged
merged 6 commits into from
May 11, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 48 additions & 48 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,51 +56,51 @@ All notable changes to this project will be documented in this file. See [standa

* add getCapabilities method to Search interface ([#42](https://github.com/awslabs/fhir-works-on-aws-interface/issues/42)) ([b274566](https://github.com/awslabs/fhir-works-on-aws-interface/commit/b274566c71899a2bd7c7d9112bfd85c889678ad4))

## [6.0.1] - 2021-01-06
### Updated
* `GetSearchFilterBasedOnIdentityRequest.operation` now includes `history-instance`
## [6.0.0] - 2020-12-21
### Added
- `SearchFilter` interface to allow `fhir-works-on-aws-search` to filter search results
- `GetSearchFilterBasedOnIdentity` interface so `fhir-works-on-aws-authz` can provide `SearchFilter` that can be used for filtering search results
- `InvalidSearchParameterError`: A new error for search to throw when search parameters are invalid
## [5.0.0] - 2020-12-11
### Added
- `ProductInfo` interface to collect product and business information about the FHIR server
## [4.0.0] - 2020-11-20
### Added
- `SmartStrategy` for passing in SMART Auth configurations
- `SmartAuthorization` for class implementing SMART Auth
### Updated
- Authorization interfaces to use `userIdentity` instead of `accessToken`
- isAuthorized renamed to verifyAccessToken
- getRequesterUserId method removed
## [3.0.0] - 2020-11-11
### Added
- Required methods for SMART on FHIR interactions
- Export UnauthorizedError to be usable
- Required interfaces and types for bulk data export
## [2.0.0] - 2020-09-25
### Added
- `getAllowedResourceTypesForOperation` method to `Authorization` interface.
### Updated
- `Authorization.isAuthorized` to return a promise.
## [1.0.0] - 2020-08-31
### Added
- Initial launch! :rocket:
## [6.0.1] - 2021-01-06

### Updated
* `GetSearchFilterBasedOnIdentityRequest.operation` now includes `history-instance`

## [6.0.0] - 2020-12-21

### Added
- `SearchFilter` interface to allow `fhir-works-on-aws-search` to filter search results
- `GetSearchFilterBasedOnIdentity` interface so `fhir-works-on-aws-authz` can provide `SearchFilter` that can be used for filtering search results
- `InvalidSearchParameterError`: A new error for search to throw when search parameters are invalid

## [5.0.0] - 2020-12-11

### Added
- `ProductInfo` interface to collect product and business information about the FHIR server

## [4.0.0] - 2020-11-20

### Added
- `SmartStrategy` for passing in SMART Auth configurations
- `SmartAuthorization` for class implementing SMART Auth

### Updated
- Authorization interfaces to use `userIdentity` instead of `accessToken`
- isAuthorized renamed to verifyAccessToken
- getRequesterUserId method removed

## [3.0.0] - 2020-11-11

### Added
- Required methods for SMART on FHIR interactions
- Export UnauthorizedError to be usable
- Required interfaces and types for bulk data export

## [2.0.0] - 2020-09-25

### Added
- `getAllowedResourceTypesForOperation` method to `Authorization` interface.

### Updated
- `Authorization.isAuthorized` to return a promise.

## [1.0.0] - 2020-08-31

### Added

- Initial launch! :rocket:
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
"local": "node .",
"prepublish": "tsc"
},
"dependencies": {},
"dependencies": {
"winston": "^3.3.3",
"winston-transport": "^4.4.0"
},
"devDependencies": {
"@types/jest": "^26.0.19",
"@types/node": "^12",
Expand Down
5 changes: 0 additions & 5 deletions src/fhirConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ export interface Server {
url: string;
}

export interface Logging {
Bingjiling marked this conversation as resolved.
Show resolved Hide resolved
level: 'debug' | 'info' | 'warn' | 'error';
}

export interface Resource {
operations: TypeOperation[];
fhirVersions: FhirVersion[];
Expand Down Expand Up @@ -160,7 +156,6 @@ export interface FhirConfig {
productInfo: ProductInfo;
auth: Auth;
server: Server;
logging: Logging;
profile: Profile;
validators: Validator[];
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ export * from './errors/UnauthorizedError';
export * from './errors/TooManyConcurrentExportRequestsError';
export * from './errors/InvalidSearchParameterError';
export * from './validator';
export { makeLogger } from './loggerBuilder';
export { stubs } from './stubs';
46 changes: 46 additions & 0 deletions src/loggerBuilder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { createLogger, Logger } from 'winston';
import Transport from 'winston-transport';

class SimpleConsole extends Transport {
log(info: any, callback: () => void) {
setImmediate(() => this.emit('logged', info));
const msg = [info.meta, info.message];
if (info[Symbol.for('splat')]) {
msg.push(...info[Symbol.for('splat')]);
}
carvantes marked this conversation as resolved.
Show resolved Hide resolved

// Use console here so request ID and log level can be automatically attached in CloudWatch log
/* eslint-disable no-console */
switch (info[Symbol.for('level')]) {
case 'debug':
console.debug(...msg);
break;
case 'info':
console.info(...msg);
break;
case 'warn':
console.warn(...msg);
break;
case 'error':
console.error(...msg);
break;
default:
console.log(...msg);
break;
}
/* eslint-enable no-console */

if (callback) {
callback();
}
}
}

// eslint-disable-next-line import/prefer-default-export
export function makeLogger(metadata?: any, logLevel: string | undefined = process.env.LOG_LEVEL): Logger {
return createLogger({
level: logLevel,
transports: [new SimpleConsole()],
defaultMeta: { meta: metadata },
});
}
Loading