Skip to content

Instantly share code, notes, and snippets.

@enricodeleo enricodeleo/smart-log.js
Last active Aug 29, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.