Created
April 27, 2017 18:12
-
-
Save wbotelhos/22c4f35a75ec92b0e319b8ca186e8f09 to your computer and use it in GitHub Desktop.
Winston Singleton (Prototype)
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
| const winston = require('winston'); | |
| const Logger = (function() { | |
| var instance; | |
| function Logger() {} | |
| Logger.prototype.logger = new winston.Logger({ | |
| exitOnError: false, | |
| transports: [ | |
| new winston.transports.Console({ | |
| handleExceptions: true, | |
| json: process.env.NODE_ENV == 'production' | |
| }) | |
| ] | |
| }); | |
| return { | |
| getInstance: function() { | |
| if (instance == null) { | |
| instance = new Logger(); | |
| instance.constructor = null; | |
| } | |
| return instance; | |
| } | |
| }; | |
| })(); | |
| module.exports = Logger.getInstance().logger; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment