Created
May 3, 2023 18:16
-
-
Save christopherbauer/fb9dd52bf1e923bf31868d8dd8da6614 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
type LogMessage = (message: string | JSON) => void; | |
/** | |
* This is a defined interface for logging that closely resembles the winston logging methods. It is unlikely we will want the | |
* interface itself to change (ie calling static logger.info/error/debug/etc methods) but we may want to be able | |
* to swap out winston should we decide we want a different framework. With this we will | |
* not depend on exposed details of the winston interface when using our logger elsewhere in the application, | |
* and if we swap it out in the future it will be as simple as calling the underlying logger via the static method | |
* declarations | |
*/ | |
class logger { | |
static info: LogMessage = winstonLogger.info; | |
static error: LogMessage = (message) => { | |
if (message instanceof Error) { | |
winstonLogger.error({ error: message }); | |
} else { | |
winstonLogger.error(message); | |
} | |
}; | |
static debug: LogMessage = winstonLogger.debug; | |
} | |
logger.info("test"); | |
export default logger; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment