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:
<cfscript>
adminObj = createObject("component","cfide.adminapi.administrator");
adminObj.login("admin");
debugger = createObject("component", "cfide.adminapi.debugging");
logfolder = debugger.getLogProperty("logdirectory");
</cfscript>
<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.
Archived Comments
That is pretty awesome. So I am guessing that I could just dump out the adminapi object to find out the other methods...I am really hoping that their is some sort of datasource method. That would be awesome.
Although I didn't see the dsn method, I did like looking through all of the methods. That was fun.
I did find this article just now though, not sure how old it is-
http://svn.riaforge.org/cfa...
So this is where the magic happens-
<cfset admin_object = createObject("component","cfide.adminapi.datasource")>
<cfdump var="#admin_object#">
I wouldn't dump the CFCs. Just visit them in your browser.
http://www.yourserver.com/c...
Where XXXX is the name of the CFC. You will get a nicely documented HTML page.
You don't need the adminapi for datasources.
<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...
The AdminAPI CFCs probably use the same serviceFactory. But - I would not recommend you use the serviceFactory like that in production. Yes it works now, but you are not guaranteed it will work in the future, whereas the AdminAPI is the _documented_ way to use these features.
well, I don't think I'd recommend using any of it in production. I assumed Brandon was asking out of either curiosity or a need to dump the info out for auditors or something.
I think it would be fair/ok to use the Admin API in production.
I'm trying to build a custom log file viewer and found this post. I had this exact question, so thanks for answering it Ray!
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.
here is a solution that doesn't require the admin's password. it relies on the fact that the config settings are stored in a wddx packet format in a file called neo-logging.xml:
<cffile action="READ" file="#Server.ColdFusion.RootDir#\lib\neo-logging.xml" variable="wddxData">
<cfwddx action="WDDX2CFML" input="#wddxData#" output="loggingConfig">
<cfset logDirectory = loggingConfig.logDirectory>
I wonder how did you guess that property name was "logdirectory" ?
Remember that CFCs are selfdocumenting. Actually open up that debugging.cfc in your browser and you will see the method and the values are listed.
@Onelookup - easy, by using cfdump, i.e.
<cfdump var="#loggingConfig#">
@cfjedimaster : You're right. Using getMetaData() or getComponentMetadata() provides infos about it. CFMX 9 Admin API sources files are not user readable. Now I wonder why didn't I think about those relfection function before asking my question :)
@Jay : Thanks. It's strange but my neo-logging.xml file does not contains "logdirectory" property declaration. On the other side I don't want to rely on these files as they may be change and/or depend or CFMX version evolutions.