Skip to content

Instantly share code, notes, and snippets.

@wbotelhos
Created April 27, 2017 18:12
Show Gist options
  • Select an option

  • Save wbotelhos/22c4f35a75ec92b0e319b8ca186e8f09 to your computer and use it in GitHub Desktop.

Select an option

Save wbotelhos/22c4f35a75ec92b0e319b8ca186e8f09 to your computer and use it in GitHub Desktop.
Winston Singleton (Prototype)
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