I don’t think it’s a good idea to leave
statements in production code, it’s a good idea to prevent your site from breaking if you accidentally do. I include this condition in the first script that loads on the page of most of my projects
if (typeof console == "undefined") {
window.console = {
log: function () {}
};
} |
This JavaScript simply defines an empty function if the console is not available in the browser so stray log statements don’t break production for your valuable customers.
In a recent project I wanted to be able to dynamically set a production flag in JavaScript. Doing so would allow me to keep my production analytics free from dev and staging environment events. Because my dev and staging environments don’t run on a .com domain extension I was able to go with this simple script
var de = document.location.hostname.split('.');
de = de[de.length - 1];
window.prod = (de == 'com') ? true : false; |
Then when I need code to only respond when in production it’s as easy as
if(window.prod) {
// do awesomeness
} |
Splitting up the domain in JavaScript to set the production flag has been working well and I’m quite happy with it so far. If you have suggestions or want to share what you have done, please share in the comments below.
tldr;
Run in terminal:
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --enable-logging --v=1&
tail -f ~/Library/Application\ Support/Google/Chrome/chrome_debug.log
If you are wondering how to know just about everything that Google Chrome is doing, you can enable verbose logging to a file. If you are running on a Mac, you can follow similar steps to launch Google Chrome in verbose logging mode.
- Make sure Google Chrome is not already running
- Open Terminal
- Find path to Google Chrome that most closely resembles the following
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome
- Once verified, launch Google chrome with verbose logging flag by running verified path with flags
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --enable-logging --v=1
- Find logging file, chrome_debug.log, that most likely lives at
~/Library/Application\ Support/Google/Chrome
- Watch the file for updates using tail or some other application
tail -f ~/Library/Application\ Support/Google/Chrome/chrome_debug.log
This is using Google Chrome version 21

Google Chrome Logging

Google Chrome logging to Terminal
Web Resources:
http://www.chromium.org/for-testers/enable-logging
http://peter.sh/experiments/chromium-command-line-switches/
http://superuser.com/q/157484/2861

Was recently working on a WordPress instance for a client where we have a cloned version of the production installation in dev. Since WordPress stores its settings in the database it would redirect to the production instance when I tried to log into the WordPress admin on the dev instance. Thankfully, the fix was fairly simple.
- SSHed into the dev instance
- logged into MySQL database
- updated ‘wp_options’ table rows where ‘option_name’ is ‘siteurl’ and ‘home’ and set it to the dev url instead of the production url