dump to file

Ketan Jetty
enthusiasm for technology

dump to file

The DumpToFile() is created to help developers dump coldfusion objects to a file for debugging purpose. You can dump objects like cfcatch, query, query result, session, variables and any coldfusion variables using this function.

DumpToFile()
<!--- dumpToFile :: dumps a max of 5 objects to a file. --->
<cffunction name="dumpToFile" access="public">
	<cfargument name="data1" required="no" type="any">
	<cfargument name="data2" required="no" type="any">
	<cfargument name="data3" required="no" type="any">
	<cfargument name="data4" required="no" type="any">
	<cfargument name="data5" required="no" type="any">
	<cfargument name="pfn" required="no" type="string">

	<cfset aPFN = "c:/dump/zDump_#DateFormat(now(),'yyyy-mm-dd-')##TimeFormat(now(),'HH-mm-ss-lll')#.htm">
	<cfif IsDefined("arguments.pfn") AND len(trim(arguments.pfn)) GT 0>
		<cfset aPFN = "#arguments.pfn#">
	</cfif>

	<cfsavecontent variable="dumpVar">
		<cfoutput>
		Time: #now()#<p>
		<cfif IsDefined("arguments.data1")><cfdump var="#arguments.data1#"><hr></cfif>
		<cfif IsDefined("arguments.data2")><cfdump var="#arguments.data2#"><hr></cfif>
		<cfif IsDefined("arguments.data3")><cfdump var="#arguments.data3#"><hr></cfif>
		<cfif IsDefined("arguments.data4")><cfdump var="#arguments.data4#"><hr></cfif>
		<cfif IsDefined("arguments.data5")><cfdump var="#arguments.data5#"><hr></cfif>
		</cfoutput>
	</cfsavecontent>
	
	<!--- force the thread to sleep for 100ms, to avoid overwriting the dump file --->
	<cfset thread = CreateObject("java", "java.lang.Thread")>
	<cfset thread.sleep(100)>
	
	<!--- create "C:/dumps" folder --->
	<cfif NOT DirectoryExists("c:/dump")>
		<cfdirectory action="create" directory="c:/dump">
	</cfif>

	<cffile action="write" file="#aPFN#" output="#dumpVar#" />
</cffunction>

How to use DumpToFile() in your code
<!--- how to use dumpToFile --->
<cfset monitorObj = CreateObject("component","monitor")>

1. dump to custom file [optional]
<cfset monitorObj.dumpToFile("arg1", "arg2", "arg3", "arg4", "arg5", "c:/someFile.htm")>

2. dump upto 5 objects
<cfset monitorObj.dumpToFile("arg1", "arg2", "arg3", "arg4", "arg5")>

3. dump single object
<cfset monitorObj.dumpToFile("arg1")>
	
Result: 
zdump-2007-12-31-17-27-33-147.htm file will be created under c:\dump\ 
which contains the objects dump info

coldfusion


CF Quick Reference


Ginger CMS
the future of cms, a simple, easy and intutive content management system ... more


CFTurbine
cf prototyping engine, generates boilerplate code and ... more


Jrun monitor
monitor and timely auto-restart to avoid Jrun hang ... more


Inheritance Config.
uses OOPs inheritance to create configuration file ... more


Real Estate App.
complete real estate application using data from MLS ... more


Search Engine Lite
create your own search engine for your web site ... more