I'm deploying 2 ears in Weblogic 10, A and B. In both of them I have a "log4j.properties" file. At the startup, when the first ear is loading, the logs are to the right file "A.log", but when the second ear is loading, all logs are going to the "B.log" file, even logs related to the first ear.
I missed something... any idea ?
Thanks
Edit/Solution :
Classloader issue.
Add to the weblogic-application.xml :
<wls:prefer-application-packages>
<wls:package-name>org.apache.log4j.*</wls:package-name>
</wls:prefer-application-packages>
Thks to everyone :)
It would be my guess that the log4j library that is used by the Weblogic server is used in both your web applications.
If this is the case, both web apps would share a root classloader serving the global libraries loade by Weblogic.
If your web apps each provide a copy of log4j, and if you can choose to load the application classes before the server classes (I don't know Weblogic but for WebSphere the setting is 'classloader mode: parent first / parent last') that might solve your problem.
Honestly it's hard to tell from here but you can try these:
1) check if the logger names in both of your log4j property files are unique.
2) I think that the .properties file are not cached on disk but still deleting the application
deployment directories (should be separate for both the EAR's )
Related
According to jboss doc, the settings from server file logging.properties file are
used when the server boots up until the logging subsystem kicks in.
In the same document, it is said that if we want to set logging rules in the deployed application, we should put one of
logging.properties
jboss-logging.properties
log4j.properties
log4j.xml
jboss-log4j.xml
files into META-INF or WEB-INF/classes. META-INF - for EAR, either of these places - for WAR and JAR. (I have JAR). I had put log4j.properties into resources/META-INF, webapp/META-INF (this one appears later in jar on the highest layer), and in webapp/WEB-INF/classes. All of them I made with different patterns so that I would recognize them when they'll appear.
Also, I added all the other 4 files into all these three places. With different patterns, again. All are present in the jar/META-INF and other appropriate places. But none of them is launched when deployed in the server. Even more, when I edit JBoss's logging.properties, the logging changes according to these changes, which means that the server pays no attention at all to any of those logging configurations in the application, even after it "kicks in".
All logging that I see after app deployment, is some server info logging about memory use. Not a line from the app. Even in the case when the browser gets something as error 500, the log is empty.
JBoss AS 6.1
I am facing a little strange issue while deploying web service to WAR file.
If I deploy the application via Netbeans IDE it is going under \standalone\deployments directory.
However, if I deploy the war file from Admin Console it is always getting deployed at \standalone\tmp directory.
Please guide on this issue. The deployment should go under \standalone\deployments directory only.
The deployment should go under \standalone\deployments directory only
You are quite not right.
It is not an issue. It is what it is.
standalone/deployment folder stand there only for "hot-deployment" functionality available only with standalone mode.
So, Netbeans uses it. You can do the same just by saving EAR or WAR into standalone/deployment and server will pick it. (default scan interval is 5 sec.)
but Admin console or CLI is only (and standard) way to deploy application on domain. In domain mode deployment folder is not in use and there is no deployment scanner.
Then when you use console it goes common way - deploys as on domain regardless is it domain or standalone server.
Updated / follow-up:
In general it is better to keep .properties file(s) out of deployment, in separate location. It is main idea behind them - to be able to change properties without application rebuilding and redeploying. Usually properties are different in different environments (DEV/UAT/PROD)
So there are 2 most popular solutions:
store properties in different location add that location to class path and access them through ClassLoader.getResourceAsStream() mechanism
store properties in different location, pass that location through system (or -D) variable and access them as file. for JBoss you can place your .properties under configuration directory. there is already JBoss variable. Kind of jboss.config.dir (or such, you can find it in Admin console, I do not have JBoss right now).
But of course sometime it still needed to access resources inside WAR/EAR - in that situation it is pretty much the same as first solution above.
Just be sure your .properties file(s) are accessible through to ClassLoader (in class path) and use them from ClassLoader.getResourceAsStream (or if you use Spring point it as "classpath:" not as "file:".
I am exploring options with log4j to write messages with the same package to different log files depending on the application. Both applications are WARs deployed to a web server. They both use some shared packages, say com.ps.foo. My use case is that I would like com.ps.foo messages to write to service.log when its executed withing the service WAR, and web.log when it executed within the web WAR.
We need the log4j configuration to be external to the WAR (in our local filesystem) so we can change logger properties without a redploy/restart of the web server, or else I would simply keep each log4j configuration packaged in each WAR.
I can specify the log4j configuration file as a -D option on the JVM, but then I am relegated to using the same log4j configuration. I cannot use the same log4j configuration file as I would not be able to qualify com.ps.foo with the application, my understanding is that log4j only cares about classes.
My current design is to add a listener to each application that initializes log4j with its own unique log4j configuration when the servlet context initializes. I would then have an application specific log4j configuration and specify com.ps.foo in each.
Any nudge in the right direction would be great.
To elaborate on that, I have a Tomcat server version 7.0.27 running Java 1.6.0_27.
I have two wars, each with their own log4j jar, also using slf4j with slf4j-log4j. Each war has it's own configuration file (log4j.xml).
war 1 should use file log-1.log and war 2 should use file log-2.log but both are logging into log-1.log.
I've checked there are no other log4j jars in the tomcat installation so I'm not sure where the problem is. I've also turned off shared class loading but that made no difference. My next step is to turn on verbose class loader logging and/or start debugging log4j but maybe someone here knows why this is and can save me some time. Thanks for any input on this.
Update:
Ok think I got this one. The log4j xml files are fine. After doing a verbose:class I can see that log4j.jar is only getting loaded once and from neither web application.
I'm working with Documentum. They have a runtime jar required to use their libraries that is an empty jar with a manifest file. The manifest points to a bunch of jars. In other words, they don't use maven... Anyway ... one of those jars happens to be logj4 found in the Documentum installation. So it seems both webapps are using that one. I think this is the problem. To be confirmed...
If you are placing Documentum's runtime jar on your top-level classpath, and that runtime jar is referencing log4j.jar, then it will only load once. You don't have to use that runtime jar, though, or you can use it in just your Documentum .war, if one is non-Documentum.
You didn't post your properties file but i can think of some reasons:
You don't have an appender that writes to the different files, i.e you need appender1 to write to log1.log and appender2 writing to log2.txt
You have the appenders set up right but both the applications are using the same logger, so they both write to the same file.
You have 2 loggers, each with its own appender, but in your code you are not initializing the correct logger:
//there is no logger called com.sample, so it defaults to root logger that has appender that writes to log1.txt
Logger logger = Logger.getLogger(com.sample.MyClass.class);
If you post your properties file and your logger init code it'll be easier to help you.
Currently when I deploy a war file to Tomcat it can be downloaded from the URL via something like foo.com/myapp.war.
Most places recommend that you put an entry in a .htaccess file to prevent public access to any war files, or failing that an equivalent entry in your Apache config.
Unfortunately, my host does not provide access to the Apache config (although I can access Tomcat confs) and .htaccess files do not work for all Tomcat/Java related hosting environments. Pretty disappointing. They have been rather unhelpful in this respect.
Without resorting to something like "finding another host" (other than this issue they are fine - I'd rather stay here until my app grows too big), is there anything else I can do to prevent public users accessing my war files, yet still allow Tomcat to deploy the apps when it scans them?
For example, is it possible to specify one directory for Tomcat to scan for war files yet have it deploy the war into the public directories?
Thanks.
It is probably better to ask at https://serverfault.com/. It all boils down to how Tomcat is setup.
The vanilla setup will have a folder called webapps under CATALINE_HOME. You put your WAR archives there (they get auto-extracted and deployed). These folders will not be accessible from HTTP (you cannot download WAR archives from some URL like /webapps/my-test.war). These apps in webapps folder are deployed to some context roots. For example an application my-test.war will by default get deployed as yourhost.com/my-test/.
If you can download your WAR archives from foo.com/myapp.war maybe you can check out what does the CATALINA_HOME/webapp/ROOT app is doing. By default this is deployed under the foo.com. Ask from the host the Tomcat configuration files to figure what kind of custom configurations are they using.
You can place your .war files in any location Tomcat has access to. But you will have to tell Tomcat about it, so it picks them up. You can do this by placing a configuration XML file in
<CATALINA_HOME>/conf/Catalina/localhost/myWebapp.xml
There are samples on what to put into that file myWebapp.xml, e. g. here, step "4)". And of course, the official documentation.