Last active
August 29, 2015 14:20
-
-
Save enricodeleo/099c6c668b37e7cd98c1 to your computer and use it in GitHub Desktop.
A hopefully smart solution for console.logging messages during development without affecting production apps
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
DEVELOPMENT = true; //global variable, I use this to adapt my js app behavior accordingly | |
// I want console.log just during development | |
if ( DEVELOPMENT ) { | |
smLog = function(log, type) { | |
var args = [ 'log', 'info', 'debug', 'warn', 'error' ]; // valid methods for `console` | |
var type = type || 'log'; // the second argument is optional, defaults to log | |
var type = ( args.indexOf( type ) ) > -1 ? type : 'log'; // defaults to log if the second argument is not valid (eg a typo) | |
console[type](log); | |
}; | |
} | |
// I can safely use smLog allover the js app, it will do nothing in production | |
smLog = ( typeof vcLog == 'function' ) ? vcLog : function noop() {}; | |
//EXAMPLE USAGE | |
smLog('Hi, I am a smart log. I won\'t be shown in production ;)', 'debug'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment