Skip to content

Instantly share code, notes, and snippets.

@enricodeleo
Last active August 29, 2015 14:20
Show Gist options
  • Save enricodeleo/099c6c668b37e7cd98c1 to your computer and use it in GitHub Desktop.
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
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