Skip to main content
Inspiring
August 6, 2024
Answered

"File not found" error is not output to exception.log

  • August 6, 2024
  • 2 replies
  • 2106 views

I use ColdFusion2021 update13, uses 2 logs that output to the api.log file (other logs output to other files)
 - one uses log4j2 (of update13) with CreateObject("java", "org.apache.logging.log4j.LogManager"),
 - the other uses my own build class CreateObject("java", "MyApiLog") (simply only logger.warn(str))
(both use 2 separate .properties files)
and uses the error-page <location>/Error404.cfm</location> handler in web.xml


After starting app server
At the Login screen (e.g. localhost:8500/index.cfm), when I access a non-existent file (e.g. localhost:8500/index.cfma)
the Error404.cfm runs OK and a "File not found" error (coldfusion.filter.ExceptionFilter$ApplicationExceptionWrapper: File not found: /Error404.cfm The specific sequence of files included or processed is: '''') is output to exception.log (up to here everything is OK)


After login ok (eg: localhost:8500/home/index.cfm), when I access a non-existent file (eg: localhost:8500/home/index.cfma)
the Error404.cfm runs OK but a "File not found" error is not output to exception.log but to the api.log
Why is the cause?

    This topic has been closed for replies.
    Correct answer VietTruong

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


    Charlie, BKBK

    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!

    2 replies

    Charlie Arehart
    Community Expert
    Community Expert
    August 11, 2024

    I have a different take than bkbk's reply today.  Rather then being concerned about you causing "too many changes happening at the same time", my concern is that you are juggling (and making us all juggle) too many variables.

     

    1) For example, you're showing cf as on Windows and Linux--with the latter being cf on Jboss as a war. I appreciate that you were making the point that the problem happens on both. But since War deployment of cf is niche (limited in number)--and on jboss specifically is still more niche--let's stick with discussing what you experience with CF on Windows, unless and until you really have need to make a distinction between the two variants. That will simplify things here. 

     

    1a) Second, your comments show running your Windows deployment of cf is as a cf instance called mywebapp. That was not indicated in your first post.

     

    Indeed, I replied talking about how use of port 8500 implies your storing code in the cfusion/wwwroot, and you didn't correct me/us that you use /mywebapp/wwwroot. You simply showed using it in reply, and it's a subtle difference we had to discern. It might even be an important distinction: you'd definitely need to configure and look for things in different folders reflecting the correct instance. (And FWIW, your linux/jboss results then show you using cf's provided cfusion.war there, which I realize is the default war file name, but it could confuse matters for some trying to follow along.)

     

    But perhaps more than important, when you show using port 8500, which was that on? Windows or Linux? Because when cf is installed as you have on Windows (NOT as a war), it defaults to using port 8500 for the cf admin and it uses the wwwroot (and logs) of the cfusion instance. Any new instance gets its own port, and a folder for the instance as a sibling to cfusion. 

     

    1b) So could you just discuss things simply in the context of Windows and perhaps do things only in your cfusion instance? This will both simplify things for us and also increase the chance for you that more people reading along can relate (since the number of folks running cf as multiple instances is a minority). 

     

    2) But most important, you're really throwing a curve ball with this whole matter of your java logging. And I get it: it's fundamental to what you want to do. But in the course of trying to understand how things are different for you since the move from CF2018 to cf2021, you've introduced not only the variety of differences I've relayed here, but it seems you're especially wanting to understand how 404 handling differs for you between cf2021 and 2018...and that on top of your own Java-based logging. Again, it's just too many variables.

     

    2a) I'd strongly suggest you reduce your testing to one thing: in a stock deployment of cf2021 (on windows, in the cfusion/wwwroot, using port 8500),what happens for you when you run your 4 base scenarios?

     

    Then introduce different variables, like adding a cflog, or adding your custom tag, or modifying any cf xml files. Then perhaps later try using a different instance.

     

    Perhaps by starting from that "back to square one" approach, something may be more clear to you. Or it may be more clear to us.

     

    3) Finally, I caught one key point you made, that the logging of things differed based on when you had or had not "logged in". That's certainly interesting, and you may want to elaborate on that.

     

    Perhaps that's even possibly the most important point for you--but it's being lost in a flood of other concerns (and competing variables) being raised here.

     

    Please make your testing as simple as possible. You may even find the answer on your own, suddenly. 🙂 

    /Charlie (troubleshooter, carehart. org)
    Inspiring
    August 13, 2024

    BKBK, Charlie
    Because my presentation is too complicated, I really apologize.
    I will try to answer and simplify it step by step.

     

    BKBK

    1. Did you test by adding a separate Application.cfm file in the folder /home? If so, what was the result?

    => There is already an Application.cfm file in the mywebapp\wwwroot\ folder, and I have no intention of using the Application.cfm file anywhere else. So I didn't do this test.

     

    2. You appear to be running a Java application on the same Virtual Machine as ColdFusion, but separately from ColdFusion. If so, why? ColdFusion is itself a Java application. You could just integrate a Java application within ColdFusion.
    => I just run Coldfusion, which has some java classes integrated under the folder: mywebapp\wwwroot\WEB-INF\..\classes\(my package xxx)\MyApiLog.class (and .java)

     

    3. No, I don't think exception.log is overwritten. Exception.log is automatically created and configured by ColdFusion itself, and should be located at C:\ColdFusion2021\mywebapp\logs\exception.log in your installation. Is the file present at that location?
    => Yes, there is C:\ColdFusion2021\mywebapp\logs\exception.log (i mean exception.log)

     

     

    Charlie
    Thank you so much for showing me the details.

    1)
    => The problem occurs on both, but let's just discuss CF on Windows.

     

    1a)
    => Because of security I changed the post without noticing. I'm really sorry. (windows port is not 8500 but 85xx, like 8502)

     

    1b)
    => Yes, for simplicity we only discuss CF on windows

     

    2)
    => Your analysis is so accurate.
    The problem arose when I went to upgrade from CF2018(log4j1) to CF2021(log4j2)

     

    2a)
    => My 4 base scenarios was run at localhost:8502 on window (Once again, I'm really sorry about the port.)
    exception.log
    -- step 1 start --
    "Error","http-nio-8502-exec-4","08/09/24","16:24:42","MyApp","checkLog Type=user Message=[Start] CALL login.cgi: 08/09/2024 16:24:42 236"
    "Error","http-nio-8502-exec-4","08/09/24","16:24:42","MyApp","checkLog Type=User Message="
    -- step 1 end --

    -- step 2 start --
    "Error","http-nio-8502-exec-8","08/09/24","16:25:23","","File not found: /indexx.cfm The specific sequence of files included or processed is: C:\ColdFusion2021\mywebapp\wwwroot\indexx.cfm''"
    coldfusion.runtime.TemplateNotFoundException: File not found: /indexx.cfm
    at coldfusion.filter.PathFilter.invoke(PathFilter.java:165)
    ..(omit)
    at java.base/java.lang.Thread.run(Thread.java:834)
    -- step 2 end --

    -- step 3 start --
    "Error","http-nio-8502-exec-1","08/09/24","16:25:58","MyApp","checkLog Type=refer Message=URL:'http://localhost:8502/home/index.cfm' | SESSION-ID:'25414FE0AD8D..'"
    "Error","http-nio-8502-exec-1","08/09/24","16:26:01","MyApp","checkLog Type=api Message=request Api.getApi1: [..]"

     

    api.log (first line is log from my own java class "MyApiLog")
    2024-08-09 16:26:01 - [SessionID] 25414FE0AD8D.. - [api] Api.getApi1 - [code] 200 - [time] 98ms
    2024-08-09 16:26:02 - checkLog Type=api Message=response Api.getApi1: {..}
    2024-08-09 16:26:02 - checkLog Type=user Message=api call: url=http://xxx, method=Api.getApi1, time=923ms.
    2024-08-09 16:26:05 - checkLog Type=User Message=
    -- step 3 end --

    -- step 4 start --
    2024-08-09 16:43:58 - File not found: /home/indexx.cfm The specific sequence of files included or processed is: C:\ColdFusion2021\mywebapp\wwwroot\home\indexx.cfm''
    coldfusion.filter.ExceptionFilter$ApplicationExceptionWrapper: File not found: /home/indexx.cfm The specific sequence of files included or processed is: C:\ColdFusion2021\mywebapp\wwwroot\home\indexx.cfm''
    at coldfusion.filter.ExceptionFilter.logErrorTofile(ExceptionFilter.java:477) [chf20210013.jar:development]
    ..(omit)
    at java.lang.Thread.run(Thread.java:834) [?:?]
    -- step 4 end --


    In the output log above, there are 2 points to note that I don't understand as below:

    a/ In step 3:
    When the Api.getApi1 method (in my own java class) is called (last line of exception.log file)
    the log handle starts transferring output to the api.log file (first line, up to here it's still OK)
    but it does not return to the output in the exception.log file but continues to output in the api.log file

    (from the 2nd line onwards in api.log, if it go back and output in exception.log it will be ok, api.log file should have only one red line)

    b/ The "File not found" in step 2 is slightly different from step 4 in that it has the word "Error" at the beginning of the line.

    (maybe due to layout pattern)

     

    3)
    => Yes, There is once difference before (had not logged) and after (had logged) calling Api.getApi1 (in my own java class)
    When the api has not been called, the log handle seems to output correctly exception.log
    But after calling the api, the log handle does not return to output log at exception.log anymore.

     

    Inspiring
    August 16, 2024

    I would like to add more information: cf2021_update10 OK but cf2021_update11 NG.

    I'm checking again for my update 11..

    Charlie Arehart
    Community Expert
    Community Expert
    August 6, 2024

    Does the home folder have a different application.cfc or .cfm file? If so, that could explain the difference, if it has no similar 404 or other error handler. 

    /Charlie (troubleshooter, carehart. org)
    Inspiring
    August 6, 2024

    There is only an Application.cfm file, and has no other error handler.

    Charlie Arehart
    Community Expert
    Community Expert
    August 6, 2024

    Ok, but do you understand how the mere presence of that application file will cause a difference in processing between the two calls you list?

    /Charlie (troubleshooter, carehart. org)