140 likes | 310 Views
Better Logging in ColdFusion. With examples for MX 7 Enterprise and all lower versions. How Logging Works. Webserver logging Third Party logging Application logging. Webserver Logging. Text files OR Database Huge amount of useless data Usually need a separate program to view
E N D
Better Logging in ColdFusion With examples for MX 7 Enterprise and all lower versions
How Logging Works • Webserver logging • Third Party logging • Application logging
Webserver Logging • Text files OR Database • Huge amount of useless data • Usually need a separate program to view • Usually ignored • Bulky
Third Party Logging • No control • Only what they give you • No control
Application Logging • Allows for better control • More control and playing with the data = more overhead • Can be a bottleneck • Slower user sessions
Solution • Throw the logging to another service • ColdFusion MX 7 Enterprise: • Asynchronous Gateway Services • ColdFusion MX 7 Pro (and earlier) • Application scope
Solution • Take all the data you want to store • Throw it to somewhere else • Have the data manipulated and stored ‘outside’ the user session • Results in clean, tight data
Asynchronous Gateways • Set up in the ColdFusion Admin • Calls a CFC • Is invoked by using the SendGatewayMessage() function • Sends a structure to the CFC • All work done ‘outside’ the user session
Asynchronous Gateways • <CFCOMPONENT output="false"> • <cffunction name="SiteLog" access="public" returntype="void" output="false"> • <cfargument name="CFEvent" type="struct" required="yes"> • </cffunction> • </CFCOMPONENT>
Asynchronous Gateways • sLogData=StructNew(); • sLogData.method="SiteLog"; • sLogData.Query_String=CGI.Query_String; • sLogData.Path_Info=cgi.Path_Info; • sLogData.Script_Name=cgi.Script_Name; • sLogData.SiteID=1; • sLogData.LogType=1; • sLogData.cfid=client.CFID; • sLogData.cftoken=client.CFTOKEN; • sLogData.REQUEST_METHOD=CGI.REQUEST_METHOD; • sLogData.HTTP_REFERER=cgi.HTTP_REFERER; • sLogData.REMOTE_ADDR=cgi.REMOTE_ADDR; • sLogData.http_user_agent=cgi.http_user_agent; • SendGatewayMessage('Asynch Logger', sLogData);
Application Gateways • Works with all versions of ColdFusion with CFAPPLICATION • Stores same structure to an application structure • Structure is read by a scheduled task • REMEMBER TO LOCK!!!