application is not logging in jboss 5 - jboss

Need help with jboss logging.I am new to jboss application server. I am able to start the application server and i do see in the server log that jboss has started. But when i click on the application and surf around the application that i have deployed i dont see any logging and i am wondering why.I have tried doing this in jboss-log4j.xml
<appender-ref ref="CONSOLE"/>
<priority value="INFO" />
<appender-ref ref="FILE"/>
<priority value="INFO" />

You should create a new appender for your application in log4j.xml:
<appender name="MYAPPENDER" class=""org.jboss.logging.appender.DailyRollingFileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="${jboss.server.log.dir}/filename.log"/>
<param name="Threshold" value="DEBUG"/>
<param name="Append" value="true"/>
<!-- 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"/>
<!-- The full pattern: Date MS Priority [Category] (Thread:NDC) Message\n
<param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
-->
</layout>
And then specify a category after it:
<category name="com.my.package" additivity="false">
<priority value="DEBUG" />
<appender-ref ref="MYAPPENDER"/>
</category>
Where com.my.package is the (top level) package of your application. All classes in this package and its sub-packages will be logged to MYAPPENDER.

Related

Enable logging for JBOSS class loading

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.

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.

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.

How in jboss write traces to separate trace file

How in JBoss to write traces to separate file?
I would like to see traces about org.hibernate.SQL and org.hibernate.type in separate trace file.
I added next appender and categories to jboss-log4j.xml but it does not help - jboss still writes traces into server.log.
<appender name="HIBERNATE" class="org.jboss.logging.appender.DailyRollingFileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="/u1/trace/sql.log"/>
<param name="Append" value="true"/>
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n"/>
</layout>
</appender>
<category name="org.hibernate.SQL">
<priority value="DEBUG"/>
<appender-ref ref="HIBERNATE" />
</category>
<category name="org.hibernate.type">
<priority value="TRACE"/>
<appender-ref ref="HIBERNATE" />
</category>
Adding appenders to a category is "additive" meaning that the new appender is logged to in addition to the existing root appender. You need to explicitly stop it from doing that:
<category name="org.hibernate.SQL">
<priority value="DEBUG"/>
<appender-ref ref="HIBERNATE" additivity="false"/>
</category>
The following setup works for me:
<category name="com.foobar.gearbox" additivity="false">
<priority value="DEBUG" />
<appender-ref ref="GB-FILE" />
</category>