Determining the location of ColdFusion's log files

This post is more than 2 years old.

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.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Archived Comments

Comment 1 by Brandon Hansen posted on 2/12/2009 at 10:04 AM

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.

Comment 2 by Brandon Hansen posted on 2/12/2009 at 10:13 AM

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...

Comment 3 by Brandon Hansen posted on 2/12/2009 at 10:18 AM

So this is where the magic happens-
<cfset admin_object = createObject("component","cfide.adminapi.datasource")>
<cfdump var="#admin_object#">

Comment 4 by Raymond Camden posted on 2/12/2009 at 5:04 PM

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.

Comment 5 by JC posted on 2/13/2009 at 12:38 AM

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...

Comment 6 by Raymond Camden posted on 2/13/2009 at 12:42 AM

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.

Comment 7 by JC posted on 2/13/2009 at 1:09 AM

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.

Comment 8 by Raymond Camden posted on 2/13/2009 at 1:12 AM

I think it would be fair/ok to use the Admin API in production.

Comment 9 by Gareth posted on 11/13/2009 at 11:04 PM

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.

Comment 10 by Jay posted on 6/8/2010 at 3:08 AM

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>

Comment 11 by onelookup posted on 2/2/2012 at 7:16 PM

I wonder how did you guess that property name was "logdirectory" ?

Comment 12 by Raymond Camden posted on 2/2/2012 at 7:54 PM

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.

Comment 13 by Jay posted on 2/3/2012 at 9:50 AM

@Onelookup - easy, by using cfdump, i.e.

<cfdump var="#loggingConfig#">

Comment 14 by OneLookup posted on 2/21/2012 at 3:55 PM

@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.