I have a coldfusion website, and at one point we put in a log – whenever a certain type of code was run, that code was logged. Now we’d like to take it out, but still have the option of putting it back in, so we’re planning on finding every time (there are probably hundreds) this code was logged and commenting out the logging code. This seems quite tedious to me and I was wondering if there’s some sort of way to mark code as testing and automatically enable/disable it by changing the settings in one place… I think I’ve seen functionality like this in other languages. Is this possible in ColdFusion?
Share
The way I would handle this is by configuring some sort of global application variable (e.g.
doLogging) that you can switch on and off and check when needed. If it is set totruethen log, otherwise don’t.For example in
Application.cfcyou could set up this variable:And then check for it where needed in your code:
You will have to change your existing code though to use this new method, but managing it in future would be easier.
Hope that helps!
EDIT: changed variable names to be more sensible and added an example of use.