Skip to content

Instantly share code, notes, and snippets.

@aqual3o
Created May 4, 2019
Embed
What would you like to do?
Custom logger which can be dynamically turned on/off
/* 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