Enable logging for JBOSS class loading - class

How do we enable logging to debug class loading issues in JBoss 5.x. If it is under JBOSS_HOME/server/xxxxx/conf to configure jboss-log4j.xml, should we need to add any piece of code or is there any other way to enable tracing.

You can turn on logging in two places:
In JVM - you should just pass the extra switch -verbose:class. You can put these switch in your run.conf file in JAVA_OPTS variable definition.
Turn logging in jboss-log4j.xml file. You should place in the file such definition:
<category name="org.jboss.classloader">
<priority value="DEBUG"/>
</category>

It worked for me. I did add like below.
<appender name="CLASSLOADING" class="org.jboss.logging.appender.RollingFileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value= "${jboss.server.log.dir}/classloading.log"/>
<param name="Append" value="false"/>
<param name="MaxFileSize" value="5000KB"/>
<param name="MaxBackupIndex" value="10"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %m%n"/>
</layout>
</appender>
<category name="org.jboss.classloading">
<priority value="TRACE"/>
<appender-ref ref="CLASSLOADING"/>
</category>

You can also enable logs in command prompt or pass as parameters to the JBoss server using IDE as:
set "JAVA_OPTS=%JAVA_OPTS% -Xms2048m -Xmx4096m -XX:MaxPermSize=256m
-Dorg.jboss.resolver.warning=true -Dorg.apache.camel.jmx.disabled=true
-Djboss.server.log.threshold=DEBUG -Dsun.rmi.dgc.client.gcInterval=3600000
-Dsun.rmi.dgc.server.gcInterval=3600000"
Here we are also increasing the memory since writing debug results in a file/console increases memory consumption. Sometimes if we do not increase the memory, it causes a permGem error.

Related

Access to JBoss4 log4j file While JBoss Is Running

I am running JBoss 4.0.5.GA and--I assume--it's included log4j package, both on OS X Mountain Lion. I have configured ../server/site/conf/log4j.xml to capture startup/shutdown messages in a separate file:
<appender name="SERVER_EVENTS" class="org.jboss.logging.appender.RollingFileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="${jboss.server.log.dir}/server_events.log"/>
<param name="Append" value="false"/>
<param name="ImmediateFlush" value="true"/>
<param name="MaxFileSize" value="500KB"/>
<param name="MaxBackupIndex" value="1"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
</layout>
</appender>
<category name="org.jboss.system.server.Server">
<priority value="INFO" />
<appender-ref ref="SERVER_EVENTS"/>
</category>
This works as far as capturing the startup/shutdown lines. I am using a LaunchAgent to watch that server_events.log file for changes. I have verified that the LaunchAgent loads, and is functional.
The LaunchAgent responds at the following times:
When run.sh kicks off and the server_events.log file is truncated.
On server shutdown, when a group of log entries ends with "Shutdown complete."
The problem I'm having is capturing the "Started in ..." message. After much Googling, I have an idea what the problem is, and I am unsure if a solution even exists. I believe the message is not getting captured because JBoss has "a hold" on the file while it's running. You can see above where I am explicitly requesting that JBoss "ImmediateFlush" the messages. I was under the impression that that is the default, but I can see in Finder that the file is 0 bytes, but watching the file opened in Sublime Text 2 reveals the startup message.
Is there any way to ensure that the startup message be written to disk immediately after it gets sent? Or am I out of luck since I'm running such an old version of JBoss?

Can I have more than 1 <appender> stanza for the same log file in a jboss-log4j.xml?

I'm working with my first jboss application server and am having some issues with the log files. Currently there is a bug in the software that is constantly streaming errors in the log file, each day I get a 708MB log file, and this quickly fills the HD space of the server.
In the jboss-log4j.xml I have 2 <appender> stanza's, one that rolls the log file each day, and a second that limits the log files to 10MB and keeps only the last 20 logs. Currently only the first stanza seems to be working. Based on this I think I can only have 1 <appender> stanza and need to merge these two....
Am I on the right track? If so can you provide some tips how I can merge these two together?
<!-- A time/date based rolling appender -->
<appender name="FILE" class="org.jboss.logging.appender.DailyRollingFileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="${jboss.server.log.dir}/server.log"/>
<param name="Append" value="false"/>
<!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
</layout>
</appender>
<!-- A size based file rolling appender -->
<appender name="FILE" class="org.jboss.logging.appender.RollingFileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="${jboss.server.log.dir}/server.log"/>
<param name="Append" value="false"/>
<param name="MaxFileSize" value="10MB"/>
<param name="MaxBackupIndex" value="20"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
</layout>
</appender>
You can have more than one appender - default is to have a file appender for the log file and another for the console.
It looks like in your code you are writing to the same file in both cases, which probably
does not make much sense and also does not sound like what you want from the description you gave.
It is not possible to have two <appender> nodes writing to the same name='FILE'.
It is also not possible to merge these two <appender>'s into one stanza.

log4net error in NUnit: "Attempted to append to closed appender named []."

When I run some integration tests via NUnit, everything works, including logging. When I run any test a second time, no exception is thrown, but logging ceases to work. Instead, log4net writes this to the console:
log4net:ERROR [TextWriterAppender] Attempted to append to closed appender named [].
Here is the log4net configuration:
<log4net debug="true" >
<appender name="console"
type="log4net.Appender.ConsoleAppender, log4net">
<layout type="log4net.Layout.PatternLayout,log4net">
<param name="ConversionPattern"
value="%d{ABSOLUTE} %-5p %c{1}:%L - %m%n" />
</layout>
</appender>
<root>
<priority value="DEBUG" />
<appender-ref ref="console" />
</root>
<logger name="NHibernate">
<level value="WARN" />
</logger>
<logger name="NHibernate.SQL" >
<level value="DEBUG" />
</logger>
</log4net>
The setup code is in a static constructor in the SUT:
log4net.Config.XmlConfigurator.Configure();
I managed to get the same error with a variety of other appender settings. What causes this error? I want to know what the cause is so I know how to fix it, and also how to reproduce this in a production scenario (if that is possible) so I can keep it from happening to production code.
I am using NHibernate 2.0.1.GA and the log4net version that comes with it (1.2.10.0).
Well if you look at the error it says [TextWriterAppender] this means log4net is trying to to append the log message to a TextWriter whereas the config which you gave doesn't have any.
Either there is another config file with a log4net tag being loaded or in code you are anywhere calling up LogManager.Shutdown()

Rolling File appender usage

What is a rollingfile appender ?
I want my jboss to delete logs either exceeding a maximum size or exceeding a certain date.
People on this forum have suggested me to use rollingfile appender.
How do I configure it in jboss-log4j.xml file ?
Here is an example:
<!-- A time/date based rolling appender -->
<appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="server.log"/>
<param name="Append" value="false"/>
<!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
</layout>
</appender>
Btw this is taken from our server's jboss-log4j.xml file - if you check your default server installation, I am fairly sure you find a similar configuration there ;-) Moreover, I guess if you add
<param name="MaxFileSize" value="100KB"/>
to the above, you get it roll over upon reaching the specified size.
For more info on appenders, see the Log4J manual.

Log4j Grouping application logs

I am trying to group logs of multiple related applications to a single log file.
For example I have 3 applications A1.esb, A2.esb, A3.esb.
I want all the logs from these 3 applications get logged to a single log file called A.log.
Similarly, I want B.log for B1.esb, B2.esb and B3.esb.
I am using log4j in JBoss application server.
I have tried to use TCLFilter but I only succeeded in getting individual applications logging to individual log files. As in, A1.esb logging to A1.log, A2.esb logging to A2.log and so on. But I couldn't figure out a way of grouping these loggings.
Thanks a lot guys for your response.
I have managed to fix it by reading some documentation on log4j for jboss.
All I had to do was to specify an appender per application group and inside each appender, I would have a filter chain.
So my log appender shall look like the following.
<appender name="A" class="org.apache.log4j.FileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"></errorHandler>
<param name="Append" value="false"/>
<param name="File" value="${jboss.server.home.dir}/log/A.log"/>
<param name="Threshold" value="INFO"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>
</layout>
<filter class="org.jboss.logging.filter.TCLFilter">
<param name="AcceptOnMatch" value="true"/>
<param name="DeployURL" value="A1.esb"/>
</filter>
<filter class="org.jboss.logging.filter.TCLFilter">
<param name="AcceptOnMatch" value="true"/>
<param name="DeployURL" value="A2.esb"/>
</filter>
<filter class="org.jboss.logging.filter.TCLFilter">
<param name="AcceptOnMatch" value="true"/>
<param name="DeployURL" value="A3.esb"/>
</filter>
<filter class="org.apache.log4j.varia.DenyAllFilter"/>
</appender>
and so on for Group B, which would have B1.esb, B2.esb and B3.esb.
Define an appender you will use for these three logs:
<appender name="A" class="org.jboss.logging.appender.DailyRollingFileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="${jboss.server.log.dir}/A.log"/>
<param name="Append" value="true"/>
<param name="Threshold" value="INFO"/>
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
</layout>
</appender>
Then route your packages to this logger with additivity=false
<category name="A1.esb" additivity="false">
<priority value="INFO"/>
<appender-ref ref="A"/>
</category>
<category name="A2.esb" additivity="false">
<priority value="INFO"/>
<appender-ref ref="A"/>
</category>
<category name="A3.esb" additivity="false">
<priority value="INFO"/>
<appender-ref ref="A"/>
</category>
I hope you are using different packages for each application.