16

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

isapir
  • 21,295
  • 13
  • 115
  • 116
CFUser
  • 2,295
  • 5
  • 32
  • 37

3 Answers3

24

ColdFusion 9 added the "writeLog" function which allows you to do this. http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WS48D04B65-0694-44e9-9E35-F9D7C9152B6C.html

Terry Ryan
  • 1,911
  • 15
  • 13
5

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">
isapir
  • 21,295
  • 13
  • 115
  • 116
3

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"

Adam Cameron
  • 29,677
  • 4
  • 37
  • 78
Stephen Moretti
  • 2,442
  • 1
  • 18
  • 29
  • Doesn't it have to be: ? – jrduncans Nov 30 '10 at 18:53
  • It didn't work for me without using # in ColdFusion 8. I'm not sure when/why that format is required, but hopefully it'll help someone else if they had the problem I did... – jrduncans Dec 02 '10 at 22:17
  • Yeah, the *quotes* are optional, but the pound-signs are required (all versions of ColdFusion, and at least Railo 4.1 and OpenBD 3.0). I've tweaked the code above accordingly. – Adam Cameron Apr 04 '13 at 00:44