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

Commit

Permalink
Update formatting, revert changelog update
Browse files Browse the repository at this point in the history
  • Loading branch information
zheyanyu committed May 6, 2021
1 parent 804cdf7 commit 3baa9fd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 30 deletions.
6 changes: 0 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### Features

* Add Winston logger builder for other components to use

### [8.2.1](https://github.com/awslabs/fhir-works-on-aws-interface/compare/v8.2.1...v8.1.1) (2021-04-06)

### [8.1.1](https://github.com/awslabs/fhir-works-on-aws-interface/compare/v8.1.0...v8.1.1) (2021-04-06)


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fhir-works-on-aws-interface",
"version": "8.2.1",
"version": "8.1.1",
"description": "FHIR Works on AWS hosted on AWS Lambda",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ export * from './errors/UnauthorizedError';
export * from './errors/TooManyConcurrentExportRequestsError';
export * from './errors/InvalidSearchParameterError';
export * from './validator';
export { getLogger } from './loggerBuilder';
export { makeLogger } from './loggerBuilder';
export { stubs } from './stubs';
38 changes: 16 additions & 22 deletions src/loggerBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,34 @@
import { createLogger, format } from 'winston';
import { createLogger, Logger } from 'winston';
import Transport from 'winston-transport';

const { combine, splat, timestamp, printf } = format;

const myFormat = printf(info => {
let msg = `${info.message} ${info.timestamp} `;
if (info.meta) {
msg += JSON.stringify(info.meta);
}
return msg;
});

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

// 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);
console.debug(...msg);
break;
case 'info':
console.info(msg);
console.info(...msg);
break;
case 'warn':
console.warn(msg);
console.warn(...msg);
break;
case 'error':
console.error(msg);
console.error(...msg);
break;
default:
console.log(msg);
console.log(...msg);
break;
}
/* eslint-enable no-console */

if (callback) {
callback();
Expand All @@ -42,11 +37,10 @@ class SimpleConsole extends Transport {
}

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

0 comments on commit 3baa9fd

Please sign in to comment.