
1271
DEVELOPING
COLDFUSION 9 APPLICATIONS
Using External Resources
Las
t
upda
te
d 8/5/2010
Example: logging messages
The following asynchronous CFML event gateway CFC uses the
cflog
tag to log a message to a file in the ColdFusion
logs directory. The CFC takes a message with the following fields:
•
file
The name of the file in which to place the message. The default value is defaultEventLog.
•
type
The
cflog
type attribute to use. The default value is info.
•
message
The message text.
<cfcomponent>
<cffunction name="onIncomingMessage" output="no">
<cfargument name="CFEvent" type="struct" required="yes">
<cfscript>
if (NOT IsDefined("CFEvent.Data.file")) {
CFEvent.Data.file="defaultEventLog"; }
if (NOT IsDefined("CFEvent.Data.type")) {
CFEvent.Data.type="info"; }
</cfscript>
<cflog text="#CFEvent.Data.message#"
file="#CFEvent.Data.file#"
type="#CFEvent.Data.type#"
thread="yes"
date="yes"
time="yes"
application="yes">
</cffunction>
</cfcomponent>
The following minimal CFML page tests the event gateway:
Sending an event to the CFML event gateway that is registered in the
ColdFusion Administrator as Asynch Logger.<br>
<cfscript>
status = false;
props = structNew();
props.Message = "Replace me with a variable with data to log";
status = SendGatewayMessage("Asynch Logger", props);
if (status IS True) WriteOutput('Event Message "#props.Message#" has been sent.');
</cfscript>
Using the example event gateways and gateway applications
ColdFusion provides several example event gateways and applications in the
cf_root
\WEB-INF\cfusion\gateway
directory on J2EE configurations or the
cf_root
\gateway directory on server configurations. These gateways provide
example code that you can examine or use in developing your gateways. They are intended as examples only, and are
not complete, product-quality, implementations.
Example event gateways
The gateway\src\examples directory and its subdirectories include the sources for the example event gateways.
Compiled versions are located in the gateway\lib\examples.jar file. This document briefly describes the event gateways
and their functions. For more detailed information, see the code and comments in the files.
Содержание COLDFUSION 9
Страница 1: ...Developing Applications ADOBE COLDFUSION 9...