How do you keep debug code out of production? How do you keep debug code out of production? javascript javascript

How do you keep debug code out of production?


The most simple method

define("DEBUG", true);if (DEBUG) {    echo "Debug Method";}

For js its similar.


One method is with an environmental variable. In your server configuration, you could set an environmental variable to say debug or not. The production servers would be configured to false, and the development to true. That way all you do in the code is check the environmental variable:

In PHP:

if (getenv('DEBUG_MODE')) {    var_dump($foo);}

That way, there's no way to forget, since it'll automatically turn itself off. But if you REALLY need to turn it on in production, just flip the switch...