I get duplicate entries in log file.

Community Beginner ,
Apr 14, 2021 Apr 14, 2021

Copy link to clipboard

Copied

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?

Views

114

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct Answer

Adobe Community Professional , Apr 15, 2021 Apr 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)...

Likes

Translate

Translate
Adobe Community Professional ,
Apr 15, 2021 Apr 15, 2021

Copy link to clipboard

Copied

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-application...

 

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 (server troubleshooter, carehart.org)

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 16, 2021 Apr 16, 2021

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Apr 16, 2021 Apr 16, 2021

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 16, 2021 Apr 16, 2021

Copy link to clipboard

Copied

Thanks, Dave.  That makes a lot of sense, and seems safer/more proper. 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Apr 16, 2021 Apr 16, 2021

Copy link to clipboard

Copied

More complicated, anyway. Charlie's solution is just as safe and proper to me, if you're the one using the tag.

 

Dave Watts, Eidolon LLC

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Apr 16, 2021 Apr 16, 2021

Copy link to clipboard

Copied

LATEST

Thanks, guys. And to be clear, what I shared in the rest of my first reply was indeed about using the thistag.executionmode, and I pointed to the docs showing its use. 🙂 I didn't elaborate it, simply because removing the closing slash would suffice in this case.

 

It's always a balancing act, deciding how much to write. And I tend to get it wrong it seems, which is my cross to bear. 


/Charlie (server troubleshooter, carehart.org)

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines