Simple CFML Trick - Add logging to ColdFusion Administrator

Earlier today I filed an ER to add logging to the ColdFusion Administrator. This would add simple auditing to actions done within the administrator. So for example you could see when a user added a DSN, or when another user tweaked mail settings. In theory this should be easy to implement, and I think it would be a great addition. If you agree, don’t forget that you can vote for bugs on the public bug tracker so add yours to the request. On a whim though I thought I’d try to see if I could hack it in. I know that the administrator hasn’t really been updated a lot lately (except for new settings!) and I guessed - correctly - that it still made use of Application.cfm, not Application.cfc.

For the heck of it, I just dropped this in my /CFIDE/Administrator folder as a new Application.cfc file:

component {

public boolean function onRequest(string req) {
	include "Application.cfm";
	include arguments.req;
	writelog(file="admin", text="User #getauthuser()# running #req#?#cgi.query_string#");
	return true;

} </code>

And guess what? It worked like a charm:

“Information”,”jrpp-107”,”03/15/10”,”14:21:41”,”CFADMIN”,”User admin running /CFIDE/administrator/settings/server_settings.cfm?targeted=false”
“Information”,”jrpp-109”,”03/15/10”,”14:21:41”,”CFADMIN”,”User admin running /CFIDE/administrator/navserver.cfm?”
“Information”,”jrpp-111”,”03/15/10”,”14:21:42”,”CFADMIN”,”User admin running /CFIDE/administrator/settings/limits.cfm?”
“Information”,”jrpp-101”,”03/15/10”,”14:21:43”,”CFADMIN”,”User admin running /CFIDE/administrator/settings/server_settings.cfm?”
“Information”,”jrpp-109”,”03/15/10”,”14:21:45”,”CFADMIN”,”User admin running /CFIDE/administrator/settings/memoryvariables.cfm?”

Obviously it isn’t as nice as it could be, but it took all of two minutes to write. The CFC above will only work in ColdFusion 9, but you could convert it to old school tags in a few additional minutes.

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support.

Lafayette, LA