1

I've got a logging function (can't use cflog) included in application.cfm and my .cfm pages can access this, but any components I use give me a "Variable LOGGER is undefined." error.

application.cfm

<cfinclude template="logging.cfm">

logging.cfm

<cffunction name="logger" >
 ...
</cffunction>

Any ideas as to what I'm doing wrong?

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
blank
  • 17,852
  • 20
  • 105
  • 159

1 Answers1

10

because the way components work is that a component can't see the "variables" scope outside of itself, and when you <cfinclude> your logging.cfm, it's including those functions into the page's variable scope. in order for your component to call those functions, you might do this:

<cfinclude template="logging.cfm">

<cfset request.logger = variables.logger>

and then in your <cfcomponent>, you could call request.logger(whatever).

But honestly, this feels backwards to me. Instead, why not a Logger.cfc that contains a function named "log", and then when you want to log something, you just do:

<cfinvoke component="my.Logger" method="log" message="#mylogmessage#">
Tomalak
  • 332,285
  • 67
  • 532
  • 628
marc esher
  • 4,871
  • 3
  • 36
  • 51