Skip to main content
Known Participant
April 14, 2021
Answered

I get duplicate entries in log file.

  • April 14, 2021
  • 1 reply
  • 739 views

I put a <cflog> command in a tag called ccilog.  This allows me to turn log entries on/off depending on a session variable, while still allowing the full functionality of the <cflog> command. When I use it, though, all my log entries are duplicated. 

 

The full tag is this:

<cfparam name="Attributes.application" >
<cfparam name="Attributes.file" default="cci-out" >
<cfparam name="Attributes.text" >
<cfif ! isdefined("session.debug")>
        <cfset session.debug = false>
</cfif>

<cfif session.debug>
        <cflog application="#attributes.application#" file="#attributes.file#" text="#attributes.text#">
</cfif>

An example call is this:

<cf_ccilog file="adipostlog" application="yes"  text="Process Documents"/>

The entry in adipostlog looks like this:

"Information","ajp-nio-127.0.0.1-8016-exec-8","04/13/21","16:11:04","CCI-QUASI","Process Documents"
"Information","ajp-nio-127.0.0.1-8016-exec-8","04/13/21","16:11:04","CCI-QUASI","Process Documents"

 If I replace my tag with a simple <cflog>, it works fine.

I would rather not wrap all my log entries with the <cfif>.

Any thoughts?

    This topic has been closed for replies.
    Correct answer Charlie Arehart

    There is a simple answer, and then an additional explanation that may help some readers.

     

    First, just take off the closing slash in your self-closing cf_ccilog tag. 🙂 The problem will stop. As for why, and what was happening, and why you may not have found an answer more readily, you can read on.

     

    What you're using here is not a "command" or simply a "tag" as you say, but specifically what CF calls a "custom tag". For readers not familiar, it's a file of a given name (in your case, ccilog.cfm) where you put in code to run, and then you call it as you have with cf_ccilog. That's a very old concept in CF, and one you don't hear people talk about much ever.

     

    The thing is, it was designed to potentially have subtags, where you would then have a closing tag </cf_ccilog>, and there was provision of a variable called this.executionmode that could detect if you were running the code in the first or second "pass". In your case, your diligence to use a self-closing tag got you into this trouble, as CF was indeed now seeing that as the same as using a closing tag (which is technically true) and it was calling the cfm page twice. 🙂

     

    This stuff is documented, but again you'd have to have known you were using a "custom tag" to have found it, and even then it's understandable that you may not have connected the dots:

     

    https://helpx.adobe.com/coldfusion/developing-applications/building-blocks-of-coldfusion-applications/creating-and-using-custom-cfml-tags/executing-custom-tags.html

     

    And it's also been covered over the years by various resources by myself and others. But again, the simple answer is just to remove the trailing slash. 🙂

     

    Let us know how it goes.

    1 reply

    Charlie Arehart
    Community Expert
    Charlie ArehartCommunity ExpertCorrect answer
    Community Expert
    April 15, 2021

    There is a simple answer, and then an additional explanation that may help some readers.

     

    First, just take off the closing slash in your self-closing cf_ccilog tag. 🙂 The problem will stop. As for why, and what was happening, and why you may not have found an answer more readily, you can read on.

     

    What you're using here is not a "command" or simply a "tag" as you say, but specifically what CF calls a "custom tag". For readers not familiar, it's a file of a given name (in your case, ccilog.cfm) where you put in code to run, and then you call it as you have with cf_ccilog. That's a very old concept in CF, and one you don't hear people talk about much ever.

     

    The thing is, it was designed to potentially have subtags, where you would then have a closing tag </cf_ccilog>, and there was provision of a variable called this.executionmode that could detect if you were running the code in the first or second "pass". In your case, your diligence to use a self-closing tag got you into this trouble, as CF was indeed now seeing that as the same as using a closing tag (which is technically true) and it was calling the cfm page twice. 🙂

     

    This stuff is documented, but again you'd have to have known you were using a "custom tag" to have found it, and even then it's understandable that you may not have connected the dots:

     

    https://helpx.adobe.com/coldfusion/developing-applications/building-blocks-of-coldfusion-applications/creating-and-using-custom-cfml-tags/executing-custom-tags.html

     

    And it's also been covered over the years by various resources by myself and others. But again, the simple answer is just to remove the trailing slash. 🙂

     

    Let us know how it goes.

    /Charlie (troubleshooter, carehart. org)
    EdGiojaAuthor
    Known Participant
    April 16, 2021

    You did it again, Charlie.  Thank you very much.  I have been trying to be "good" and close all my tags. 

    Community Expert
    April 16, 2021

    As Charlie pointed out, being "good" can be difficult! Charlie's answer is the quickest and most direct way to solve your problem.

     

    If you want to be able to be "good" and have the problem not happen, you can actually modify the custom tag so that it contains conditional logic that uses the value of thisTag.executionMode. In the first iteration, you'd want the logging to happen, and in the second iteration you wouldn't:

     

    <cfif thisTag.executionMode is "start">

    ... do all the stuff you want including logging that you're doing now ...

    </cfif>

     

    The only benefit here is that it will allow future uses of that tag with either a closing slash or without one, allowing it to behave the same way in either case.

     

    Dave Watts, Eidolon LLC

    Dave Watts, Eidolon LLC