Created
May 4, 2019 00:40
-
-
Save aqual3o/662fc6420df660f540f685ab719cad1b to your computer and use it in GitHub Desktop.
Custom logger which can be dynamically turned on/off
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
/* eslint no-console : off */ | |
const logger = {}; | |
let logOptions = { | |
enabled : true | |
}; | |
logger.setConfig = function (options) { | |
logOptions = options; | |
}; | |
logger.info = function (...args) { | |
if (logOptions.enabled) | |
console.info (...args); | |
}; | |
logger.error = function (...args) { | |
if (logOptions.enabled) | |
console.error (...args); | |
}; | |
logger.debug = function (...args) { | |
if (logOptions.enabled) | |
console.debug (...args); | |
}; | |
module.exports = logger; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment