Ok, I have to admit - the four year old in me wrote that title. The cfdump is the single most useful tag in ColdFusion. But what if you want to use it and store the result for later? Don't forget one of the other extremely useful ColdFusion tags: cfsavecontent. For example:
<cfsavecontent variable="thedump">
<cfdump var="#application#" label="The Application Scope">
</cfsavecontent>
This will take the entire dump and store the result in a string named thedump. Then you can use cffile to save it to the file system. If you do, I'd suggest saving it as an HTML file since cfdump contains a lot of HTML. Kind of like how the galaxy has a lot of stars. You can also cfmail it as well. Just remember to use HTML mail.
Archived Comments
i've written a small custom tag, because i had some time on my hands. Sorry, I'm using cf5 here, so you'll have to plug it in your utility cfcs yourselves ;-)
<cfparam name="attributes.OutPutPath" type="string" default="D:\"> <!--- Physical path to the saved file --->
<cfparam name="attributes.OutPutFile" type="string" default="MyBigDump.htm"> <!--- Name of the file to save --->
<cfparam name="attributes.MyVar" default=""> <!--- variable to be dumped --->
<cfparam name="attributes.MyDumpName" type="string" default=""> <!--- name of the cfdump element (>cf5) --->
<cfparam name="attributes.MyDumpExpand" type="boolean" default="1"> <!--- whether or no you want the structure to be expanded my default (>cf5) --->
<cfparam name="attributes.Append" type="boolean" default="1"> <!--- whether you want to append to current file or start from scratch --->
<cfsavecontent variable="variables.TempVar">
<cfdump var="#attributes.Myvar#" label="#attributes.MyDumpName#" expand="#attributes.MyDumpExpand#">
</cfsavecontent>
<cfif attributes.Append>
<cfset variables.ThisWriteAction = "append">
<cfelse>
<cfset variables.ThisWriteAction = "write">
</cfif>
<cffile action="#variables.ThisWriteAction#" file="#attributes.OutPutPath##attributes.OutPutFile#" output="#variables.TempVar#">
Tof
and of course, to use it:
<cfset foo = "bar">
<cf_savedump MyVar="#foo#">
Since everything is defaulted, you only need to pass the variable.
Don't forget to cfflush when done.
;)
This is probably one of the most useful little secrets with CF.
I use it extensivly when working with Paypal since when using IPN, it is hard to know what was past to you and what errors have occurred. By saving the dumps of the form and url structures to an html file, it makes it easy to know if your getting the right information from Paypal.
<cfdump>, <cflog> (who thought of these names?) and <cfsavecontent> are incredible time savers when it comes to troubleshooting/debugging and application.
I used this method to learn how flash remoting passes structures to a cfc.
For example, take a cfgrid and pass it's contents to a cfc and save the dump - you'll see that the grid is passed as an array of structures.
CFDUMP is great. But like Ray said - they're LOADED with HTML - don't try to email a large dump, it will be a mess! I've had a huge dump lock up my Outlook several times.
'don't try to email a large dump, it will be a mess! I've had a huge dump lock up my Outlook several times.'
Quite possibly the dirtiest thing ever uttered on Ray's blog.
Actually, I'd suggest the best way to "view a dump later" would be to actually use CFWDDX to save the data as XML and then use CFDUMP against the WDDX packet.
Doing this not only allows you to quickly recreate the actual data instance (incase you wanted to re-create a problem) you can very easily use CFDUMP to dump the WDDX to screen for readibility (if you don't want it known that it was converted to WDDX, just serialize to a local variable before calling CFDUMP.)
For people who have problems e-mailing themselves a CFDUMP using Outlook, trying including the CFDUMP as an external file. That way Outlook doesn't have to parse the HTML.
I use Thunderbird and it renders CFDUMP very efficiently. I can view e-mails that will hang Outlook users. The solution we used was to send the CFDUMP outputs as an attachment.
Surely Ray you could have come up with a better title for this one. I nearly killed the monitor by spraying coffee all over it I was laughing so hard.
larry
(off in the wilds of BC)
Actually I use a combination of <cfsavecontent>, and <cfdump> in combination with <cfmail> and <cflog> in my debugging. Its saved me a lot of time and effort in figuring out various problems.
regards,
larry
I have been using cfsavecontent in just the way Ray talks about a zillion times while working on the Mystic Flex 2.0 integration with CFCs. What a pain! :-)
Luckly we have given cfdump some love already in the scorpio tree and I think we have solved several of the problems (dump to a file, HTML/css dependancies, etc) that people are talking about here.
We were very tempted to put this in Mystic (just for our own use!) but since we are giving it away for free, its bug fixes only per Adobe (and Macromedia for that matter) policy. [Yes, I know that the Flex 2.0 stuff is new, but you have to have *Flex* for that]
Nice to hear about the enhancements Tom. I hope you guys advertise it a bit. It seems like some of the small, cool stuff gets forgotten. (Of course, they aren't as cool.)
For example - how many people on this thread know about the TOP attribute of cfdump?
Heh, ignore the cool, not as cool text. I got caught by my own spam checker and the rewrite didn't quite come out well. :)
Ray - thanks for the heads up on the parameters that can be passed to CFDUMP, I'd never read the livedoc on it since I just assumed that I was passing just the var over.
Also, as a first time "Ask a Jedi" blog commentor, thanks for the blog, it's the first I subscribed to ever (using Thunderbird) and your posts are awesome (and this one quite amusing).