log4j issues, or jboss issues. i almost gave up - java

I have the following situation:
- two HA singleton apps on jboss eap
- each one with its own log4j.properties file:
App1:
log4j.rootLogger=DEBUG, App1
log4j.appender.App1=org.apache.log4j.RollingFileAppender
log4j.appender.App1.append=true
log4j.appender.App1.File=${jboss.server.log.dir}/App1.log
log4j.appender.App1.MaxFileSize=10MB
log4j.appender.App1.MaxBackupIndex=10
log4j.appender.App1.threshold=TRACE
log4j.appender.App1.layout=org.apache.log4j.PatternLayout
log4j.appender.App1.layout.ConversionPattern=[%-5p] [%t] %d{yyyy MMM dd HH:mm:ss,SSS} (%C:%F:%L) - %m%n
log4j.logger.org.hibernate=DEBUG, App1
log4j.logger.com.arjuna=DEBUG, App1
log4j.logger.com.sun=ERROR,App1
log4j.logger.com.sun.xml.ws.transport.http.client.HttpTransportPipe=DEBUG,App1
App2
log4j.rootLogger=DEBUG, App2
log4j.appender.App2=org.apache.log4j.RollingFileAppender
log4j.appender.App2.append=true
log4j.appender.App2.File=${jboss.server.log.dir}/App2.log
log4j.appender.App2.MaxFileSize=10MB
log4j.appender.App2.MaxBackupIndex=10
log4j.appender.App2.threshold=TRACE
log4j.appender.App2.layout=org.apache.log4j.PatternLayout
log4j.appender.App2.layout.ConversionPattern=[%-5p] [%t] %d{yyyy MMM dd HH:mm:ss,SSS} (%C:%F:%L) - %m%n
log4j.logger.org.hibernate=DEBUG, App2
log4j.logger.com.arjuna=DEBUG, App2
log4j.logger.com.sun=ERROR,App2
log4j.logger.com.sun.xml.ws.transport.http.client.HttpTransportPipe=DEBUG,App2
both installed and running quite hmmm... with this issue:
All hibernate logs form App2 are written in App1.log
Also all com.sun.xml... logs from App2 are written in App1.log.
And non (nor hibernate nor sun.xml) are written into App2.log.
Both org.hibernate and com.sun are log managed into applications, at server level they are on ERROR level, so there is no logging in server.log.
Also, if I’m disabling App1, those two categories from App2 will be logged into the App1's log file.
It clearly is something I miss and/or I really don't know.
Now, my problem is that I need log4j to log stuff only where I’m telling it to do it.
Can anyone advise me with anything? And, hmm, I really don’t like the idea of using jboss logging settings (custom appenders in console or standalone-ha.xml).
I just want to use log4j…
Thanks to all.

Hibernate is shipped with JBoss (under modules\system\layers\base\org\hibernate) and uses internally org.jboss.logging. And org.jboss.logging is also shipped with JBoss. Hence I guess that logging initialization is only done once for the complete JVM (as org.jboss.logging is loaded through the module classloader and not through your application class loaders and static fields are classloader specific).
I would recommend (although your requirements sounds strange to me), to ship Hibernate and log4j in your application (i.e. in the lib/ folder of your applications). Then Hibernate is loaded twice, one time by the classloader for the first application and a second time by the classloader for the second application. This way the static field can exist twice.

Related

Effectively debugging Log4j framework

I wanted to implement logging for my web services.I have been playing around with Log4j. It's a really cool logging framework when it works.But when it doesn't , it's a pain to debug.
My problem is that i am trying to log to the database , but for some reason I don't see anything being logged to the table. I have no clue whats causing this.
In my log4j.xml i have the following line
<log4j:configuration debug="true"
xmlns:log4j='http://jakarta.apache.org/log4j/'>
But when i deploy and run my web service in the debug mode in Eclipse , I don't see logging related debug statements on the console.
I want to be able to see
log4j initializing and configuring the loggers. So if anything is wrong with my xml configuration i would know immediately.
log4j logging to the destination , in this case to the database. If there is a some kind of a sql/database exception I would know.
I am logging at the application level (the application is using its own log4j jar and configuration files as opposed to using the application servers logging mechanism)
My project uses log4j-1.2.17 , Eclipse Luna 4.4.0, JBoss EAP 6.4.0.
Can our log4j experts suggest ways to effectively debug log4j itself. Are there Eclipse plugins that can help alleviate the pain.

log4j generating logger file but not appending anything

The settings I have specified in log4j is as follows:
log4j.appender.F2=org.apache.log4j.RollingFileAppender
log4j.appender.F2.File=E\:/Documentum/logs/dflogger.log
log4j.appender.F2.MaxFileSize=10MB
log4j.appender.F2.layout=org.apache.log4j.PatternLayout
log4j.appender.F2.layout.ConversionPattern=%d{ABSOLUTE} %5p [%t] %c - %m%n
log4j.logger.com.myorg.mytbo.tbo=DEBUG,F2
I am trying to log information from inside TBO (defined in package com.myorg.mytbo.tbo) which is essentially a JAR deployed on jboss application server inside EMC Documentum Content Server. This specific information about Documentum server shouldn't be any concern since it still uses org.apache.log4j. When the TBO runs it creates dflogger.log but does not append any information inside it.
I suspect many reasons like:
File is getting created in readonly mode.
or may be there is some issue associated with logging for com.myorg.mytbo.tbo, for which this is somewhat similar thread, specifying PARENT_FIRST option in websphere. But I am using jboss, so if the issue is similar then can anyone tell if I need to modify jboss settings?

OpenJPA logging into a separate file in Websphere

I've a problem with OpenJPA logging and Websphere (8).
For a few days I try to redirect the OpenJPA logging information into a separate file (instead of the SystemOut log file). This is what I tried:
Changing the persistence.xml with logging information (e.g. ). Though I learned that websphere is ignoring this entry. Can I assume that this is correct?
http://pic.dhe.ibm.com/infocenter/wasinfo/v8r0/topic/com.ibm.websphere.express.doc/info/exp/ae/tejb_loggingwjpa.html tells me the same
Also the wsjpa.log property did not help.
Specifying a handler for openjpa (or openjpa.Runtime, ...) in JSR-47 configuration file does not work either (other configurations worked). What I realized here is that there is actually no openjpa logger in the java logging (java.util.logging.LogManager.getLogManager().getLoggerNames()). Does that mean that OpenJPA is not logging to a dedicated logger but just writes to SystemOut which is then processed by websphere?
I searched through all the different loggers and traces in the websphere console and tried a few, but none of them contained any openjpa logs. Can I assume that there is no other location where openjpa logs to in websphere?
To conclude: It's not working and I cannot use a handler for the openjpa logs because there are no logs generated. OpenJPA in websphere is just printing to the SystemOut which is internally used for the tracing. Does anyone have an idea what to do?
Alternatives would be:
- Use HPEL
- Script to filter the trace.log
But actually I would rather have a file handler for OpenJPA in Websphere.
Thanks for your help and I can supply you with some more information if you need that.
You can use application logging system for this purpose based on 3d party logging library for example logback.
logback is very powerful library.

Interweave events from using WebLogic and Log4j

I am using WebLogic and Log4j for my Struts application. Since Action class is not thread-safe, I assumed Action classes are cached by WebLogic and re-used for every HTTP request.
In this case, if there are multiple clients accessing the same Action class, I assume the events printed on by Log4j will be output by multiple request.
The log information would not be sequential and very difficult to interpret.
How do I resolve such issues?
First, I would like to fix some terms usage in your question. Struts is a MVC framework. Weblogic is a Java EE container. The Action functionality and life cycle does not depend on container. It is the Struts's functionality only.
You are right, since instance of Action is created per request your log will contain a mixture of log messages created by different actions.
The typically used solution is to print thread name into log (log4j supports this configuration), then use grep command on unix or find on windows to filter only relevant messages.
Here is an example of layout configuration that causes log4j to print thread name:
<layout class="org.apache.log4j.EnhancedPatternLayout">
<param name="ConversionPattern" value="%-5p %-23d{ISO8601}{GMT} [%t] %x: %c{1}(%C{1}.%M:%L) - %m%n"/>
</layout>
[%t] does the job.

GoogleAppEngine log warning

I create a default project using GoogleAppEngine for java, and when I deploy my application on google server I have the following warning message for the first request.
log4j:WARN No appenders could be found for logger (DataNucleus.Connection).
log4j:WARN Please initialize the log4j system properly.
The log is working fine, but some request are delayed by this problem.
How can I configure it correctly?
What makes you sure that this is delaying some of your requests?
GAE does not function like a standard servlet container. Behind the scenes it unloads any webapps that are idle, and then loads them in again only when it gets a new request for that webapp. This is basically equivalent to doing a complete redeploy of your application, and it doesn't even begin until after GAE has received the request. Thus any request that triggers a load operation will be noticeably delayed compared to subsequent requests.
But there are a whole lot of things going on that are contributing to the delay, and I think an uninitialized log4j setup is not making much of an actual difference.
This messages means that there is no log4j configuration is found.
You have to put an configuration for log4j, for example into file named as log4j.properties in app classpath.
Configuration, for example, would be:
log4j.rootLogger=WARN, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %t %c{1}:%M:%L - %m%n
If your project is Maven based, then the best place to put log4j.properties will be src/main/resources

Categories