views:

249

answers:

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?

+8  A: 

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#">
marc esher
thanks that's clear, but yes the last part of your answer seems to have been missed out
Bedwyr Humphreys
I've made the missing part visible. +1 to the answer.
Tomalak