16
votes

I am learning to use <cfscript>.

Is there any way I can log some messages or values inside the <cfscript>?

like outside <cfscript> I can use <cflog>, Is there any way or Tag something like that, i can use to print the messages in log file inside >

Thanks

3
Echoing Terry Ryan's comment CF9 has a much more complete cfscript implementation. - kevink
Careful! the Open Blue Dragon ColdFusion implementation doesn't offer cfscript, so if you use it you're tied to Adobe. - O. Jones
@Ollie Jones, no, he is not. He can use Railo, which has full-script CFC support. - Mohamad
@OllieJones: yeah it does. Just tested on OpenBD 3.0 - Adam Cameron
@CFUser, given you're getting differing answers for different CFML engines, it might help if you tag this with the correct engine / version? - Adam Cameron

3 Answers

24
votes
5
votes

In Lucee/Railo you can use cflog in script by removing the angular brackets and the "cf" prefix, so you can write

<cfscript>
  log text="some text" file="logfilename" type="information";
</cfscript>

this is equivalent to

<cflog text="some text" file="logfilename" type="information">
3
votes

Unfortunately on versions of ColdFusion prior to CF9 there isn't. However, what you can do is map a UDF to cflog:

<cffunction name="doCFLog">
   <cflog attributeCollection="#arguments#">
</cffunction>

inside your cfscript call the doCFLog function with the same attributes as you would cflog

eg. doCFLog(text='sometext', type='warning',application='yes', file='mylog');

Note: its not a good idea to call your methods/udf etc the same name as an existing function or tag, hence not calling the function "cflog" or "log"