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>
2 adminObj = createObject("component","cfide.adminapi.administrator");
3 adminObj.login("admin");
4
5 debugger = createObject("component", "cfide.adminapi.debugging");
6 logfolder = 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.
2 adminObj = createObject("component","cfide.adminapi.administrator");
3 adminObj.login("admin");
4
5 debugger = createObject("component", "cfide.adminapi.debugging");
6 logfolder = debugger.getLogProperty("logdirectory");
7 </cfscript>
8 <cfoutput>#logfolder#</cfoutput>
Comment 1 written by Brandon Hansen on 11 February 2009, at 11:04 PM
Comment 2 written by Brandon Hansen on 11 February 2009, at 11:13 PM
I did find this article just now though, not sure how old it is-
http://svn.riaforge.org/cfadminwsapi/test.cfm
Comment 3 written by Brandon Hansen on 11 February 2009, at 11:18 PM
<cfset admin_object = createObject("component","cfide.adminapi.datasource")>
<cfdump var="#admin_object#">
Comment 4 written by Raymond Camden on 12 February 2009, at 6:04 AM
http://www.yourserver.com/cfide/adminapi/XXXXX.cfc...
Where XXXX is the name of the CFC. You will get a nicely documented HTML page.
Comment 5 written by JC on 12 February 2009, at 1:38 PM
<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...
Comment 6 written by Raymond Camden on 12 February 2009, at 1:42 PM
Comment 7 written by JC on 12 February 2009, at 2:09 PM
Comment 8 written by Raymond Camden on 12 February 2009, at 2:12 PM
Comment 9 written by Gareth on 13 November 2009, at 12:04 PM
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.
[Add Comment] [Subscribe to Comments]