4 Replies Latest reply on Sep 9, 2006 4:53 AM by Dan Bracuk

    UDF question

    Level 7
      I'm trying to create a function that writes actions to a log file. I can do
      this manually, but I think it would be easier to do it once and call it when
      I need it.

      I have:

      <cffunction name="LogEntry">
      <cfargument name="Mode" required="yes" type="string">
      <cfset LogFileInfo="#CreateLogDate# #CreateLogTime# - #Arguements.Mode# has
      been created for email address: #form.Email#">
      <cffile action="append"
      file="c:\Inetpub\wwwroot\serenity\Logs\UserAccounts.txt"
      output=#LogFileInfo# addNewLine="yes">
      </cffunction>

      And I'm calling it using:
      <cfoutput>#LogEntry(URL.Mode)#</cfoutput>

      I keep getting a error saying that 'Element MODE is undefined in
      ARGUEMENTS.'

      Can anyone point me in the right direction as to what I'm doing wrong?

      Thanks!


        • 1. UDF question
          LeftCorner Level 1
          As a matter of reuse I would replace all the global and scoped variables in your functions with arguments or create them internally. E.g.:

          <cfargument name="Mode" required="yes" type="string">
          <cfargument name="EmailAddress" required="yes" type="string">
          <cfargument name="LogFileInfo" required="yes" type="string">

          <cfset var CreateLogDate = DateFormat(Now(), "mm/dd/yyyy">
          <cfset var CreateLogTime= TimeFormat(Now(), "hh:mm:ss tt">

          When you have global variables, form varaibles and other scoped variables in your function you are not encapsulating your function, you are making it dependent on the existance of these variables. This is turn will cause headaches with reusing this function as well cause potential bugs.

          In any regard you may want to look into the tag <cflog> which does alot of writing the log for you.
          • 2. Re: UDF question
            Dan Bracuk Level 5
            change arguements to arguments
            • 3. Re: UDF question
              Level 7
              Is there a way to add a <cfif> to the mix? If I make the cffunction
              something like:

              <cffunction name="LogEntry">
              <cfargument name="Mode" required="no" type="string">
              <cfset LogFileInfo="#CreateLogDate# #CreateLogTime# - #Arguments.Mode# has
              been created for email address: #form.Email#">
              <cffile action="append"
              file="c:\Inetpub\wwwroot\serenity\Logs\UserAccounts.txt"
              output=#LogFileInfo# addNewLine="yes">
              </cffunction>

              Since the arguement isn't required, I'd like to test to see if there is a
              value there. If not, I'll use a different value in the cfset.....

              Can this be done? If so, are you using <cfif> on Argument.Mode???

              "Dan Bracuk" <webforumsuser@macromedia.com> wrote in message
              news:edt89t$7qs$1@forums.macromedia.com...
              > change arguements to arguments
              >


              • 4. Re: UDF question
                Dan Bracuk Level 5
                You can use either cfif or cfparam with the arguments scope exactly the same way you use it for any other scope.