Created
August 19, 2011 19:19
-
-
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
This file contains hidden or 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
// 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