Posted in ColdFusion | Posted on 02-11-2009 | 3,673 views
This was asked on cf-talk yesterday but figured it would be a good tip to share here. Is there a way - via code - to determine the location of ColdFusion log files? Yes, via the Admin API:
1<cfscript>
2adminObj = createObject("component","cfide.adminapi.administrator");
3adminObj.login("admin");
4
5debugger = createObject("component", "cfide.adminapi.debugging");
6logfolder = debugger.getLogProperty("logdirectory");
7</cfscript>
8<cfoutput>#logfolder#</cfoutput>
2adminObj = createObject("component","cfide.adminapi.administrator");
3adminObj.login("admin");
4
5debugger = createObject("component", "cfide.adminapi.debugging");
6logfolder = debugger.getLogProperty("logdirectory");
7</cfscript>
8<cfoutput>#logfolder#</cfoutput>
The first two lines create an instance of the Administrator API CFC and logs in with my password. (And no, 'admin' isn't really my password. It's password.)
The next two lines use the debugging CFC to run getLogProperty("logdirectory"), which as you can guess, gets the log directory value.


I did find this article just now though, not sure how old it is-
http://svn.riaforge.org/cfadminwsapi/test.cfm
<cfset admin_object = createObject("component","cfide.adminapi.datasource")>
<cfdump var="#admin_object#">
http://www.yourserver.com/cfide/adminapi/XXXXX.cfc...
Where XXXX is the name of the CFC. You will get a nicely documented HTML page.
<cfset sf = CreateObject("java", "coldfusion.server.ServiceFactory")>
<cfdump var="#sf.DataSourceService.getDatasources()#" expand="true">
Or if you want something a bit more readable than cfdump, add this:
<cfoutput>Server,Instance,DSN,Database,Host,Username,Select,Insert,Update,Delete,Proc,Create,Drop,Grant,Revoke,Alter<br>
<cfloop list="#StructKeyList(foo)#" index="i">
#host#,#cfserv#,#foo[i].name#,#foo[i].urlmap.database#,#foo[i].urlmap.host#,#foo[i].username#,
<cfif #foo[i].select# IS "YES">Select </cfif>,
<cfif #foo[i].insert# IS "YES">Insert </cfif>,
<cfif #foo[i].update# IS "YES">update </cfif>,
<cfif #foo[i].delete# IS "YES">delete </cfif>,
<cfif #foo[i].storedproc# IS "YES">storedproc </cfif>,
<cfif #foo[i].create# IS "YES">create </cfif>,
<cfif #foo[i].drop# IS "YES">drop </cfif>,
<cfif #foo[i].grant# IS "YES">grant </cfif>,
<cfif #foo[i].revoke# IS "YES">revoke </cfif>,
<cfif #foo[i].alter# IS "YES">alter </cfif><br>
</cfloop>
</cfoutput>
And you can get even more db info if you want it. the cfdbinfo tag has lots... here's a script I wrote a while back that basically crawls and dumps out everything the specified data source has access to.
http://yougiveloveabad.name/wp-content/uploads/dbi...
It's a pity you need to enter the admin password to get the log file location, but I suppose there are security reasons.
For my own security paranoia, I don't want to put my server's password into my code. Likewise, I don't want to give it to the people using my log file viewer for them to enter via a form.
In an ideal world, CFLOG would be able to specify the log file's location. As that's not possible, I think I'll need to build my own custom logger.
<cffile action="READ" file="#Server.ColdFusion.RootDir#\lib\neo-logging.xml" variable="wddxData">
<cfwddx action="WDDX2CFML" input="#wddxData#" output="loggingConfig">
<cfset logDirectory = loggingConfig.logDirectory>
<cfdump var="#loggingConfig#">
[Add Comment] [Subscribe to Comments]