BKBK
Thank you for your response!
I say "the Error404.cfm runs OK", i mean "Missing Template Handler" has no problem.
Regarding the cfma file type i used, it was incorrect. I corrected it to use a .cfm file with any file name that doesn't exist.(as step2.cfm, step4.cfm below)
About CF2018 -> CF2021 we don't need to care anymore, we are only mention to CF2021 update10 -> update11.
About CGI too, we don't need to care anymore, we are only mention to the content we want to be logged.
The content in exception.log is logged from CF.
The content in api.log is logged from myapp (not CF).
I guess the problem might be with the log4j2 (2.17.2(CF21 update10) -> 2.20.0(CF21 update11))
In short, let's start over as below.
Premise:
\Error404.cfm (in Missing Template Handler)
..
<cf_log type="user" message="Error404 run OK" >
<cfinclude template="/errorStatic404.cfm">
\WEB-INF\...\CustomTags\Log.cfm (for debug checklog)
..
<cflog log="Application" type="ERROR" text="checkLog Type=#attributes.Type# Message=#attributes.Message#">
\step1.cfm
<cfdump var="call api by cfhttp - start">
<cfhttp method="get" url="http://xxx../apiX" result="response" resolveurl="Yes" timeout="30">
</cfhttp>
<cf_log type="api" message="log api by cfhttp">
<cfdump var="call api by cfhttp - end">
\step3.cfm
<cfdump var="call api by MyApiLog - start">
<cfset a_client=CreateObject("java", "(my package)xxx..MyApiLog")>
<cfset a_client.init()>
<cfset a_serverResult=a_client.getApi1()>
<cfdump var="call api by MyApiLog - end">
\WEB-INF\...\classes\(my package xxx)\api4j.properties
log4j.rootLogger=WARN, R5
log4j.appender.R5.Threshold=WARN
log4j.appender.R5 = org.apache.log4j.DailyRollingFileAppender
log4j.appender.R5.File = C:\\ColdFusion2021\\mywebapp\\logs\\apilog\\api.log
log4j.appender.R5.Append = true
log4j.appender.R5.DatePattern = '.'yyyy-MM-dd
log4j.appender.R5.layout = org.apache.log4j.PatternLayout
log4j.appender.R5.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} - %m%n
\WEB-INF\...\classes\(my package xxx)\MyApiLog.java
package xxx..api;
import java.io.IOException;
import java.util.Properties;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
public class MyApiLog {
public static Logger logger = Logger.getLogger(MyApiLog.class.getName());
private final String prop_file = "api4j.properties";
public MyApiLog(){
Properties props = new Properties();
try {
props.load(getClass().getResourceAsStream(prop_file));
} catch (IOException e) {
e.printStackTrace();
}
PropertyConfigurator.configure(props);
}
public void WriteLogger(String str){
logger.warn(str);
}
public Object getApi1() throws IOException {
String str = "[SessionID] 25414FE0AD8D.. - [api] Api.getApi1 - [code] 200 - [time] 98ms";
this.WriteLogger(str);
return null;
}
}
After run 4 scenarios below:
step 1/access existent-file.cfm (localhost:8502/step1.cfm)
step 2/access non-existent-file.cfm (localhost:8502/step2.cfm)
step 3/access existent-file.cfm (localhost:8502/step3.cfm)
step 4/access non-existent-file.cfm (localhost:8500/step4.cfm)
Result (NG) on CF21 update11.
(in api.log file there should be only 2 lines similar to update10 below)
application.log
-- step 1 start --
"Error","http-nio-8502-exec-2","08/19/24","11:40:11","MyApp","checkLog Type=apij Message=log api by cfhttp"
"Error","http-nio-8502-exec-2","08/19/24","11:40:12","MyApp","checkLog Type=User Message="
-- step 1 end --
-- step 2 start --
"Error","http-nio-8502-exec-3","08/19/24","11:41:18","MyApp","checkLog Type=user Message=Error404 run OK"
"Error","http-nio-8502-exec-3","08/19/24","11:41:18","MyApp","File not found: /step2.cfm The specific sequence of files included or processed is: C:\ColdFusion2021\mywebapp\wwwroot\step2.cfm''"
-- step 2 end --
-- step 3 start --
-- step 3 end --
-- step 4 start --
-- step 4 end --
exception.log
-- step 1 start --
"Error","http-nio-8502-exec-2","08/19/24","11:40:11","MyApp","checkLog Type=apij Message=log api by cfhttp"
"Error","http-nio-8502-exec-2","08/19/24","11:40:12","MyApp","checkLog Type=User Message="
-- step 1 end --
-- step 2 start --
"Error","http-nio-8502-exec-3","08/19/24","11:41:18","MyApp","checkLog Type=user Message=Error404 run OK"
"Error","http-nio-8502-exec-3","08/19/24","11:41:18","MyApp","File not found: /step2.cfm The specific sequence of files included or processed is: C:\ColdFusion2021\mywebapp\wwwroot\step2.cfm''"
coldfusion.runtime.TemplateNotFoundException: File not found: /step2.cfm
..(omit)
at java.base/java.lang.Thread.run(Thread.java:834)
-- step 2 end --
-- step 3 start --
-- step 3 end --
-- step 4 start --
-- step 4 end --
api.log (Orange lines should not be in here)
-- step 1 start --
2024-08-19 11:40:11 - log api by cfhttp
-- step 1 end --
-- step 2 start --
-- step 2 end --
-- step 3 start --
2024-08-19 11:42:29 - [SessionID] 25414FE0AD8D.. - [api] Api.getApi1 - [code] 200 - [time] 98ms
2024-08-19 11:42:29 - checkLog Type=User Message=
-- step 3 end --
-- step 4 start --
2024-08-19 11:43:38 - checkLog Type=user Message=Error404 run OK
2024-08-19 11:43:38 - File not found: /step4.cfm The specific sequence of files included or processed is: C:\ColdFusion2021\mywebapp\wwwroot\step4.cfm''
coldfusion.filter.ExceptionFilter$ApplicationExceptionWrapper: File not found: /step4.cfm The specific sequence of files included or processed is: C:\ColdFusion2021\mywebapp\wwwroot\step4.cfm''
..(omit)
at java.lang.Thread.run(Thread.java:834) [?:?]
-- step 4 end --
Result (OK) on CF21 update10 (downgraded).
application.log
-- step 1 start --
"Error","http-nio-8502-exec-5","08/19/24","11:55:20","MyApp","checkLog Type=apij Message=log api by cfhttp"
"Error","http-nio-8502-exec-5","08/19/24","11:55:21","MyApp","checkLog Type=User Message="
-- step 1 end --
-- step 2 start --
"Error","http-nio-8502-exec-8","08/19/24","11:56:11","MyApp","checkLog Type=user Message=Error404 run OK"
"Error","http-nio-8502-exec-8","08/19/24","11:56:11","MyApp","File not found: /step2.cfm The specific sequence of files included or processed is: C:\ColdFusion2021\mywebapp\wwwroot\step2.cfm'' "
-- step 2 end --
-- step 3 start --
"Error","http-nio-8502-exec-9","08/19/24","11:56:57","MyApp","checkLog Type=User Message="
-- step 3 end --
-- step 4 start --
"Error","http-nio-8502-exec-3","08/19/24","11:57:48","MyApp","checkLog Type=user Message=Error404 run OK"
"Error","http-nio-8502-exec-3","08/19/24","11:57:48","MyApp","File not found: /step4.cfm The specific sequence of files included or processed is: C:\ColdFusion2021\mywebapp\wwwroot\step4.cfm'' "
-- step 4 end --
exception.log
-- step 1 start --
-- step 1 end --
-- step 2 start --
"Error","http-nio-8502-exec-8","08/19/24","11:56:11","MyApp","File not found: /step2.cfm The specific sequence of files included or processed is: C:\ColdFusion2021\mywebapp\wwwroot\step2.cfm'' "
coldfusion.runtime.TemplateNotFoundException: File not found: /step2.cfm
..(omit)
at java.base/java.lang.Thread.run(Thread.java:834)
-- step 2 end --
-- step 3 start --
-- step 3 end --
-- step 4 start --
"Error","http-nio-8502-exec-3","08/19/24","11:57:48","MyApp","File not found: /step4.cfm The specific sequence of files included or processed is: C:\ColdFusion2021\mywebapp\wwwroot\step4.cfm'' "
coldfusion.runtime.TemplateNotFoundException: File not found: /step4.cfm
..(omit)
at java.base/java.lang.Thread.run(Thread.java:834)
-- step 4 end --
api.log
-- step 1 start --
2024-08-19 11:55:21 - log api by cfhttp
-- step 1 end --
-- step 2 start --
-- step 2 end --
-- step 3 start --
2024-08-19 11:56:57 - [SessionID] 25414FE0AD8D.. - [api] Api.getApi1 - [code] 200 - [time] 98ms
-- step 3 end --
-- step 4 start --
-- step 4 end --
Now, my problem has been solved.
I just rewrote the 2 files below in log4j2 format.
-api4j.properties (logger.api.name = API)
-MyApiLog.java (logger = context.getLogger("API");)
I would like to close this conversation.
Thank you for your help!