0

cfdump output attrribute, The What, Why and How

ColdFusion 8

The What
Starting with ColdFusion 8 Adobe added a new attribute, output, to the incredibly popular cfdump tag. The default value is browser which works exactly how it has since the tags inception.

The Why
So, why use the output attribute? Mostly at a time when the request is not going back to the browser such as a scheduled task or when the data is going to an AJAX request or Flex. Or to log something -- the advantage of using cfdump output= over cflog is cfdump will parse whatever you throw at it into a text format.

The How
cfdump takes any cf variables or pretty much any type of object and returns the data. Here is the classic cfdump of a query

<cfquery datasource="cfartgallery" name="getArtists">
SELECT artistID, city, firstname, lastname, state 
FROM artists
WHERE state = 'DC'
</cfquery>

<cfdump var="#getArtists#">

produces



Place a filename in the output attribute and ColdFusion will dump the contents in a text format to that file. If the file does not exist, CF will create it, if it does exist CF will append to it.

<cfdump var="#getArtists#" output="/artists.txt">

Here is the output in artists.txt

Note the text format of data output, instead of just dumping the html that gets returned to the browser, cf provides a lighter format for the output files.

The third option is console which if you started CF from a command prompt will dump the output to the command prompt. If not CF will place the output in the cfserver.log file. To start CF from a command prompt from a multi-instance install open up terminal and cd to /Applications/JRun/bin and enter

./JRun -start cfusion
(Windows startup would be very similar). It is possible to start up the standard edition from the command line but there is little point to doing so as CF will still send the output to cfserver.log.

To send output to the console simply set output="console":

<cfdump var="#getArtists#" output="console">

produces this in Terminal:

Macs have a handy log viewer which works with any log file and automatically refreshes to show any changes. Here is the cfserver.log after running the above code on a Mac CF Standard Edition:

Overall the output attribute adds some useful capabilities to an extremely useful tag.

tags:
ColdFusion 8
 
Another addition is the format attribute - if you specify 'text' and dump to browswer you'll get the same text based format that is used when dumping to file/console.
 
posted 182 days ago
Add Comment Reply to: this comment OR this thread
 
 
Cool. Thanks for pointing that out. You can also use format=html when the output is to a file.
 
posted 181 days ago
Add Comment Reply to: this comment OR this thread
 

Search

Sam  Farmer