This repository has been archived by the owner on Apr 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* BREAKING CHANGE: Remove logging interface export * feat: add logger builder to be used by other FHIR components
- Loading branch information
1 parent
58f099f
commit aa99182
Showing
6 changed files
with
293 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')]); | ||
} | ||
|
||
// 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 }, | ||
}); | ||
} |
Oops, something went wrong.