JBoss does not launch logging in the deployed applications - java

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

Related

Wildfly Deployment going to temp folder

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:".

Writing same package to different log files in different applications

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.

No log statement is printing using websphere 8.0

I have one application running in WAS8.
we have a jar - commons-logging-1.1.1.jar in WEB-INF/lib
we have one properties file - commons-logging.properties
the content of the file is
priority=1
org.apache.commons.logging.LogFactory=org.apache.commons.logging.impl.LogFactoryImpl
we have org.apache.commons.logging.LogFactory file in WebContent/META-INF/services
the content of the file is
org.apache.commons.logging.impl.Log4jFactory
The log files are created but nothing is written in it. It is not showing any error in the log files in log of appserver.
Please let me know if I am missing something.
Please note: if I keep commons-logging.properties in /opt/IBM/WebSphere/80/AppServer/profiles/AppSrv01/properties, then it works perfectly fine. It is writing in the log files. But as I heard it is not standard practice so I can't keep the file in that place. I have to find some alternative way.
Please help me.
If it is not a requirement to have separate log files for your web application, you can simply remove the commons-log jar and properties from your module (war) and your log statements will write to SystemOut.log according to the log level settings in the WebSphere console (which can be changed at runtime, by the way).
If you must separate application logging, you can refer to this infocenter article that lays out the combination of commons-log jar location, commons-log properties values, and application classloader settings (Parent-First, Parent-Last, commons-log.jar bundled or not, etc) to achieve the desired results.

tomcat, 2 webapps, 2 log4js, but both apps log to one file

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.

Log4j logging problem with 2 ears in Weblogic

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 )

Categories