This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JBoss/WildFly and the fly likes Issue with JBoss logging for different jboss instances running on same machine Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "Issue with JBoss logging for different jboss instances running on same machine" Watch "Issue with JBoss logging for different jboss instances running on same machine" New topic
Author

Issue with JBoss logging for different jboss instances running on same machine

Panayappan Periyakaruppan
Greenhorn

Joined: May 30, 2010
Posts: 2
We have two JBoss instances running at the same time
(For ex:
App1.war running under %JBOSS_HOME%/server/JBoss_Instance1 and
App2.war running under %JBOSS_HOME%/server/JBoss_Instance2

on the SAME machine)

Both these apps have their own LoggerClass to access Log4j instance. (We have this class in the workspace and at ANT-Build time this class goes into both the Apps' war). Structure of Class attached at the end.

Both Apps have their own ServletContextListeners which initializes their respective Loggerclasses at respective JBoss start up.

The problem is:
Both Apps creates/initializes their app.log files but only one of them succeeds in logging while other doesn't.

The way we access in our code where we need to log is -

SomeLogger logger = SomeLogger.getLogger();
/*some logic*/
logger.logInfo("ClassName.API","Log Message");

Workaround:
We created LoggerClass1 for App1 and LoggerClass2 for App2 (except different name for class, they both are identical)- Things worked awesome

Could there be a problem at the JBoss-Log4j configuration, that we are missing? Or does logging of apps in JBoss is handled at Container level rather than App level?

Any pointer or directions would be of great help.



Senthil Balakrishna
Greenhorn

Joined: Sep 27, 2011
Posts: 2
By default Jboss uses "Unified Class loaders",meaning all the java structural elements will get loaded into one class loader causing this conflict. All you need do is to define a Class loader Isolation, please refer to Jboss wiki for details.

http://community.jboss.org/wiki/ClassLoadingConfiguration


Specifying Isolation:

For .ear files, in your jboss-app.xml, add the following descriptor fragment construct to enable scoped class loading:
<jboss-app>
<loader-repository>
com.example:archive=unique-archive-name
</loader-repository>
</jboss-app>

For .war files, in your jboss-web.xml, the following template applies:
<jboss-web>
<class-loading>
<loader-repository>com.example:archive=unique-archive-name</loader-repository>
</class-loading>
</jboss-web>
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5812
    
    7

Panayappan and Senthil, welcome to Java Ranch!

@Panayappan, which version of JBoss AS? Logging was radically changed in each of the last several releases, so not knowing which version you are using makes it difficult to provide advice.


JBoss In Action
Senthil Balakrishna
Greenhorn

Joined: Sep 27, 2011
Posts: 2
Just out of curiosity, why not use JBoss logging functionality rather than handling it at application level ? That way you can control dynamically the logging levels thro' JBoss console.
Panayappan Periyakaruppan
Greenhorn

Joined: May 30, 2010
Posts: 2
Thanks Senthil and Peter.

@Peter - we are using jboss-5.1.0.GA

@Senthil - thanks for the reference link. It is a requirement that we need individual log file and hence individual log4j properties. For different apps, we might adjust log levels as and when required. That is, changing log level for one app should not affect log levels of other applications.

We will experiment the suggestion as in the reference link above and given an update.


Here is the log4j properties that we use.



log4j.rootCategory=INFO, R

#### First appender writes to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%p] %c{1} %m%n

#### Second appender writes to a file
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=${PROJ_HOME}/runtime/log/app1.log

# Control the maximum log file size
log4j.appender.R.MaxFileSize=100KB
# Archive log files (one backup file here)
log4j.appender.R.MaxBackupIndex=1

log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %c{1} [%p] %m%n
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9930
    
159

Panayappan Periyakaruppan wrote:We have two JBoss instances running at the same time
(For ex:
App1.war running under %JBOSS_HOME%/server/JBoss_Instance1 and
App2.war running under %JBOSS_HOME%/server/JBoss_Instance2

on the SAME machine)

You mean 2 separate applications each on a separate JVM? In that case I don't see how the 2 instances are interfering with each other during logging (unless you share the same file to which the logs get written).

[My Blog] [JavaRanch Journal]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Issue with JBoss logging for different jboss instances running on same machine
 
Similar Threads
Logging "FINEST" messages using java Logger
how to make log4j print out class name and line number
Obtaining access to Logger using a different Mechanism
Log4j and WSAD 5.0
log4j vs system.out.Println()