Skip to main content
2Charlie
Inspiring
Oct 8, 2015 1:46 PM UTC
Answered

How to write out a log file?

I have this function below and I tried to write the result of query to log file but it failed every time I ran. the CFLog tag as third line from the bottom. Any suggestion is much appreciated.

<cffunction name="getCommonSpotPages" access="public" returnType="query">

  <cfset var qryCSPages = queryNew("")>

  <cftry>

  <cfquery name="qryCSPages" datasource="#application.sitemap.sDSN#">

  select p.ID, s.subsiteURL, p.filename, p.DateContentLastModified, u.publicFileName, p.uploaded as bIsUploaded, s.uploadURL,

  (select fieldValue from data_fieldValue dfv where p.ID = dfv.pageID and dfv.fieldID = #application.sitemap.nPriorityFieldID# and dfv.versionState = 2 ) as nPriority,

  (select fieldValue from data_fieldValue dfv where p.ID = dfv.pageID and dfv.fieldID = #application.sitemap.sFrequencyFieldID# and dfv.versionState = 2 ) as sFrequency

  from SitePages p

  join SubSites s

  on p.SubSiteID = s.id

  left join UploadedDocs u

  on p.id = u.pageID

  where (p.expDate is null

  OR p.expDate > getdate())

  and p.pageType = 0 <!--- uploaded documents and content pages only --->

  and p.approvalStatus <> 1 <!--- // exclude inactive pages --->

  and s.siteState <> 0 <!--- // exclude inactive subsites --->

  and s.subsiteURL not like '%training%' <!--- specify all pages inside of the subsite to be exlcuded from the sitemap --->

  and s.ID not in (<cfqueryparam value="#application.sitemap.lstExcludeSubsites#" cfsqltype="CF_SQL_INTEGER" list="yes" /> ) <!--- // exclude particular subsites --->

  order by p.ID desc

  </cfquery>

  <cfcatch><cfdump var="#cfcatch#"></cfcatch>

  </cftry>

  <cflog text="#qryCSPages#" type="Information" file="queryPages">

  <cfreturn qryCsPages>

</cffunction>

    This topic is closed to new replies. Start a new post to keep the conversation going.
    WolfShade
    WolfShadeCorrect answer
    Legend
    Oct 8, 2015 2:47 PM UTC

    All the tmpResult.sql does is print the SQL that was run from within the query.

    You cannot tell CF where to save logs.  They are available at [DRIVE]/cfusion/logs - go there and look for your log.  It can also be accessed via CFAdmin, under DEBUGGING AND LOGGING.

    HTH,

    ^_^

    5 replies

    WolfShade
    Legend
    Oct 8, 2015 2:34 PM UTC

    You are sending a query object (complex) to a log as a string (simple).  If you REALLY want all of that information in a log file (if it's a lot of data, I wouldn't), you have to loop the query (if more than one record is returned) and spell out each column for each iteration.

    HTH,

    ^_^

    EX

    <cfoutput query="qryCSPages">

    <cflog text="#ID#: #subsiteURL# - #filename# - #DateContentLastModified# - #publicFileName# - #blsUploaded# - #uploadURL#." type="information" file="querypages" />

    </cfoutput>

    Translate
    2Charlie
    2CharlieAuthor
    Inspiring
    Oct 8, 2015 2:41 PM UTC

    I've modified the query with a result attribute and log the SQL property as followed but it's still not generating any log. By the way, is there a way to specify where the log file will be created? I do a search for queryPages and nothing was found.

    <cflog text="#tmpResult.SQL#" type="Information" file="queryPages">

    Translate
    WolfShade
    WolfShadeCorrect answer
    Legend
    Oct 8, 2015 2:47 PM UTC

    All the tmpResult.sql does is print the SQL that was run from within the query.

    You cannot tell CF where to save logs.  They are available at [DRIVE]/cfusion/logs - go there and look for your log.  It can also be accessed via CFAdmin, under DEBUGGING AND LOGGING.

    HTH,

    ^_^

    Translate