Tuesday, 30 October 2012

Improvements to ColdFusion's logging

G'day
This is the result of a random thought I had overnight in response to a challenge I have accessing the logs my code creates on my shared-hosted ColdFusion account with cfmldeveloper. This is my first foray into needing stuff hosted somewhere - I've not done any non-work code that I wanted to be public-facing before - and I'm finding it an interesting experience not being the master of my own rig.  I don't mean "interesting" as code for "it sux", I do mean it as "interesting".  No problem has been insurmountable yet, but I have had to revise a coupla the things I automatically do as a matter of course.


Whilst testing out this @cfbugnotifier twitter application, I was having problems with the scheduled task that polled the bugbase... it didn't seem to be running.  However when I hit the task URL in the browser, it ran fine.  This is a perennial problem people have, and it's usually something obvious (in my case it was PEBCAK: I was using the wrong URL. Groan).

My usual approach to solving this sort of thing is to stick a coupla writeLog() calls in the task code, and see how far through the process it gets.  I duly did this, and then went to go into CFAdmin to look at the logs.  Except I have a shared-hosted account, and no access to CFAdmin. So I went "nae bother, I'll just grab the files". Nuh-uh: no file system access to the WEB-INF dir either, so I could not get at the raw files.  Sod it.

So this got me thinking. It really sux that <cflog> / writeLog() only allows one to specify the log file name... not the path, and not the extension.  I really question the sense behind this: what's the benefit of ColdFusion arbitrarily forcing the location of my log files?  Other than for the convenience of the CF dev team writing the code for <cflog>, I mean (yeah, OK, that was a bit catty, I admit it).

What I thought might be quite handy would be able to specify a log descriptor - like a DSN name - in Application.cfc, eg:

this.logSettings = {
    "myLog"    = {
        path = "/path/to/myLog.log"
        // other settings?
    }
};
Then one could continue to use <cflog> / writeLog() as per usual:
<cflog log="myLog" text="My log entry">
I had a superficial look at what Log4J does in this area, and it seems to have the notion of logical names for logs, so I figure this is not a completely far-fetched notion.

Obviously I could just wrap up Log4J with my own logic, but I think this might be a handy addition to CF?  Obviously not something one would use every day, but definitely the sort of thing I could have used in the past, fairly frequently.

Before I raise an enhancement request with Adobe, any thoughts on this?

Cheers.

--
Adam