• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Problem to generate log4j log file.

 
Ranch Hand
Posts: 453
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to generate log4j log file but the log files are generated with zero infomations.
log4j.xml:

Servlet:

Result:
Image.jpg
[Thumbnail for Image.jpg]
 
Cezar Apulchro
Ranch Hand
Posts: 453
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where am I going wrong?
 
Saloon Keeper
Posts: 13886
314
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which of the loggers in your configuration file do you expect to log any messages to file for you? The root logger logs to console only.
 
Cezar Apulchro
Ranch Hand
Posts: 453
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After change problem still the same.

Result log:

Is the first time that I use the log4j.
 
Saloon Keeper
Posts: 25475
180
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Cezar Apulchro
Ranch Hand
Posts: 453
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Result:


What I must to do to solve this problem?
 
Stephan van Hulst
Saloon Keeper
Posts: 13886
314
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please delete all your log files, run the application again, tell us what happened EXACTLY and tell us what you expected to happen instead.
 
Cezar Apulchro
Ranch Hand
Posts: 453
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After change to:

Result:
 
Tim Holloway
Saloon Keeper
Posts: 25475
180
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does file conf\Catalina\localhost\EspecialidadesController.xml look like?
 
Cezar Apulchro
Ranch Hand
Posts: 453
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Only to console:

Result:

 
Tim Holloway
Saloon Keeper
Posts: 25475
180
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is totally incorrect. It should be an XML Context file.

No wonder your webapp immediately shuts down.
 
Cezar Apulchro
Ranch Hand
Posts: 453
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What I must to do?
 
Cezar Apulchro
Ranch Hand
Posts: 453
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No news?
 
Cezar Apulchro
Ranch Hand
Posts: 453
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nobody has any idea to solve this problem?
 
Stephan van Hulst
Saloon Keeper
Posts: 13886
314
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tim, how do you figure the app immediately shuts down? All I see is the standard warning that is given when a WAR is deployed to Tomcat whose context.xml contains a path attribute.

Cezar, Tim asked you to show him your deployment descriptor, not your logging configuration file.

You also didn't give a complete answer to my last question. I wanted you to delete all your log files and tell me what happens when you send a request to your controller. Did your application recreate the log files in your logging directory?

That question is meaningless now though, because you changed your configuration again. So, does your application log anything to console when you send a request to your controller? And how can you be certain that you controller is being hit by the request?
 
Tim Holloway
Saloon Keeper
Posts: 25475
180
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:Tim, how do you figure the app immediately shuts down? All I see is the standard warning that is given when a WAR is deployed to Tomcat whose context.xml contains a path attribute.



Tim Holloway wrote:
What does file conf\Catalina\localhost\EspecialidadesController.xml look like?



Cezar Apulchro wrote:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" name="EspecialidadesController">
 ....



Tomcat Log wrote:
02-May-2022 08:11:50.875 WARNING [main] org.apache.catalina.startup.HostConfig.deployDescriptor The path attribute with value [/EspecialidadesController] in deployment descriptor [C:\Program Files\Apache Software Foundation\apache-tomcat-9.0.59\conf\Catalina\localhost\EspecialidadesController.xml] has been ignored



The conf\Catalina\localhost\EspecialidadesController.xml file MUST be a Tomcat Server-Dependent Deployment Descriptor file. Tomcat deployment descriptors are not defined with a root of "Configuration", they are defined with a root of Context. Without a Context, there is no docBase to point to the actual WAR to be deployed. Thus any attempt to deploy a WAR will fail and the deployment descriptor is ignored.

The docBase is critical. If you simply plop a WAR into the TOMCAT_HOME/webapps directory, a synthetic Deployment Descriptor is created internally by Tomcat whose docBase is TOMCAT_HOME/webapps/warname, but if you explictly define one in the [t]]conf/catalina/localhost[/tt] directory, then the docBase supplied in the Context element will be used, and it does not have to be in TOMCAT_HOME/webapps or even in the Tomcat directory tree at all (I generally use /opt/com/mydomain/myappname).

So until a proper deployment descriptor is defined in conf/catalina/localhost I'd expect to see something like what I'm seeing in the Tomcat log. Attempted startup of the webapp followed by immediate shutdown.
 
Stephan van Hulst
Saloon Keeper
Posts: 13886
314
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cezar just posted the contents of his log4j configuration file, because he didn't follow your instructions properly. I'm pretty sure he did not put log4j configuration inside his context.xml.

When deploying a WAR to Tomcat from NetBeans, NetBeans just puts the context.xml file from the project into the conf/Catalina/localhost folder, renames it to the context path name, which NetBeans derives from the path attribute inside the context.xml file, and adds a docBase attibute to point to the Maven build artifact. The path attribute is NOT used by Tomcat however:

This attribute must only be used when statically defining a Context in server.xml. In all other circumstances, the path will be inferred from the filenames used for either the .xml context file or the docBase.


This is the thing that Tomcat is complaining about in the server logs: The path attribute is ignored. The rest of the context file is fine, and the application does not terminate immediately.

I know for certain that the application is running, because the latest logs that Cezar posted indicate that log4j has picked up the log4j configuration file and has parsed it successfully.

So we're back to Cezar, who needs to tell us exactly what isn't working. Just posting the server logs over and over isn't helping us. Tell us if you can hit your controller with a request. Tell us how you know that. Tell us whether the controller printed anything to console when the request hit.
 
Cezar Apulchro
Ranch Hand
Posts: 453
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry by delay, problem with my internet.
EspecialidadesController.xml:

 
Cezar Apulchro
Ranch Hand
Posts: 453
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The controller don't print anything in console.
Another question is that I receiving "No records found" from primefaces and log4j don't tell me where is the problem.
 
Cezar Apulchro
Ranch Hand
Posts: 453
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
context.xml:
 
Tim Holloway
Saloon Keeper
Posts: 25475
180
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you.

Stephan has informed me that NetBeans would have created that file for you. Normally, I'd expect to see a docBase element in it, though, since that's what's required to tell Tomcat where the WAR is actually located.

Without a docBase, I'm going to have to assume that NetBeans also built or copied the WAR into TOMCAT_HOME/webapps under the name EspecialidadesController. If no such WAR exists there, that's a problem. If one does exist, I recommend shutting down Tomcat and NetBeans, deleting directory TOMCAT_HOME/webapps/EspecialidadesController if it exists and TOMCAT_HOME/webapps/EspecialidadesController.war if it exists. Also all files in TOMCAT_HOME/temp, TOMCAT_HOME/work and TOMCAT_HOME/logs. Also delete TOMCAT_HOME/conf/Catalina/localhost/EspecialidadesController.war.xml Then rebuild, redeploy and restart the webapp. That should clean out any lingering basura and give us a better idea of what else needs to be done.
 
Stephan van Hulst
Saloon Keeper
Posts: 13886
314
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Cezar Apulchro wrote:context.xml:


This is the file inside the NetBeans project. It's what NetBeans uses to deploy the application to Tomcat.

EspecialidadesController.xml:


This is the file that has been deployed to Tomcat after NetBeans has transformed it.

The value that you entered into the path attribute suggests to me that you don't understand what this attribute is used for. The value of this attribute should be a "context path", whereas you appear to have entered a relative path to a controller.

I'm thinking that your requests simply never hit your controller because you're using the wrong URL's to make requests.

The problem is not log4j. The problem is not PrimeFaces. The problem is probably that you don't appear to understand how servlet containers route requests to applications, and how applications route requests internally.

Have you already read the Tomcat user manual to figure out what context paths are?

I suggest you start with a very simple web application that consists of nothing more than a dependency on the Servlet API and a single servlet that prints out a simple message. Don't use your IDE. Compile it by running Maven in a command line interpreter, and deploy it to Tomcat by hand. Unless you understand how to deploy your web application to Tomcat by hand, you're not ready to let your IDE do it for you.
 
Tim Holloway
Saloon Keeper
Posts: 25475
180
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To expand on what Stephan said about the <Context> xml. While Context is used to define a number of things for a webapp - including defining security and database connection pools, at a minimum, they usually have a path and a docBase. The path would be used to define the URL context that tells Tomcat which webapp will receive an incoming URL request. However, when you put a Context XML file in TOMCAT_HOME/conf/Catalina/localhost the path is ignored because Tomcat uses the Context file name as the URL context path instead. And in your case, Tomcat warned you about that in its log.

The docBase, on the other hand, is critical, since without it Tomcat doesn't have accurate information on where to find the WAR.
 
Cezar Apulchro
Ranch Hand
Posts: 453
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What did I do step by step:
1 - Uninstall Netbeans;
2 - Delete Tomcat directory;
3 - Delete C:\Users\Administrador\.m2;
4 - Install Netbeans;
5 - Unzip apache-tomcat-9.0.59-windows-x64 and create Tomcat directory;
6 - Deply - http://localhost:8080/manager/html/start?path=/ClientsJpa1&org.apache.catalina.filters.CSRF_NONCE=8F14AFD4DAA93EAC2766F0C4B07FE3D3.
And problem still the same.
Image.jpg
deploy of ClientsJpa1
deploy of ClientsJpa1
 
Cezar Apulchro
Ranch Hand
Posts: 453
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry:
5.1 - mvn clean;
5.2 - mvn install;
 
Stephan van Hulst
Saloon Keeper
Posts: 13886
314
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why would you reinstall NetBeans and Tomcat, based on what we said?
 
Cezar Apulchro
Ranch Hand
Posts: 453
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes.
 
Yup, yup, yup. Tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic