Skip to content

Instantly share code, notes, and snippets.

@nathanl
Created August 19, 2011 19:19
Show Gist options
  • Save nathanl/1157738 to your computer and use it in GitHub Desktop.
Save nathanl/1157738 to your computer and use it in GitHub Desktop.
Javascript console logging that won't bite you if it goes into production
// Simple wrapper for console.log()
//
// Does nothing unless it's turned on AND the user has a console open
//
// Usage
// - Turn on with `safeLogger.active = true;`
// - Log messages like `safeLogger.log('someString',someObject);`
safeLogger = {
// Switch on and off from console, or edit here (but don't commit)
active: false,
log: function() {
if (safeLogger.active){
try {
// Only log if the user has a javascript console open
window.console && console.log(arguments);
} catch(e){
// Something went wrong? Oh well. Do nothing.
}
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment