
Application specific logging with JBoss-6.0.0.Final
Posted by pi4630 in EJB/AS Rookie on Nov 16, 2011 2:29:09 AMYou want your application logs to be inside a specific log file only, instead of server.log.
Here's the brief instruction:
- Create a jboss-logging.xml file (you may copy it from the /server/default/delpoy directory) and put it into your project's META-INF or WEB-INF folder
- Define a context and a handler
- Refer to the handler from the root logger portion of the xml file
- Modify the file logmanager-jboss-beans.xml of your server configuration
Here's the jboss-logging.xml I use:
{code:xml}
<?xml version="1.0" encoding="UTF-8"?>
<!-- ===================================================================== -->
<!-- -->
<!-- Logging System Configuration -->
<!-- -->
<!-- ===================================================================== -->
<logging xmlns="urn:jboss:logging:6.0" context="MyAppLoggingContext">
<define-context name="MyAppLoggingContext" />
<!-- ================================= -->
<!-- Preserve messages in a local file -->
<!-- ================================= -->
<!-- A time/date based rolling handler -->
<size-rotating-file-handler file-name="${jboss.server.log.dir}/Mercurius.log"
name="MERCURIUS" autoflush="true" append="true" rotate-size="1024k"
max-backup-index="5">
<error-manager>
<only-once />
</error-manager>
<formatter>
<!-- To revert back to simple stack traces without JAR versions, change
"%E" to "%e" below. -->
<!-- Uncomment this to get the class name in the log as well as the category
<pattern-formatter pattern="%d %-5p [%c] %C{1} (%t) %s%E%n"/> -->
<!-- Uncomment this to log without the class name in the log -->
<pattern-formatter pattern="%d %-5p [%c] (%t) %s%E%n" />
</formatter>
</size-rotating-file-handler>
<!-- Limit the org.apache category to INFO as its DEBUG is verbose -->
<logger category="org.apache">
<level name="INFO" />
</logger>
<!-- Limit the jacorb category to WARN as its INFO is verbose -->
<logger category="jacorb">
<level name="WARN" />
</logger>
<!-- Limit JSF to INFO as its FINE is verbose -->
<logger category="javax.enterprise.resource.webcontainer.jsf">
<level name="INFO" />
</logger>
<!-- Limit the org.jgroups category to WARN as its INFO is verbose -->
<logger category="org.jgroups">
<level name="WARN" />
</logger>
<!-- Limit the org.quartz category to INFO as its DEBUG is verbose -->
<logger category="org.quartz">
<level name="INFO" />
</logger>
<!-- Limit the com.sun category to INFO as its FINE is verbose -->
<logger category="com.sun">
<level name="INFO" />
</logger>
<!-- Limit the sun category to INFO as its FINE is verbose -->
<logger category="sun">
<level name="INFO" />
</logger>
<!-- Limit the javax.xml.bind category to INFO as its FINE is verbose -->
<logger category="javax.xml.bind">
<level name="INFO" />
</logger>
<!-- Limit the springframework category to WARN -->
<logger category="org.springframework">
<level name="WARN" />
</logger>
<!-- Test -->
<logger category="it.bz">
<level name="DEBUG" />
</logger>
<!-- Limit Arjuna transaction manager -->
<logger category="com.arjuna.ats">
<level name="INFO" />
</logger>
<!-- Limit Hibernate <logger category="org.hibernate"> <level name="INFO"
/> </logger> -->
<!-- Limit Ajax4jsf <logger category="org.ajax4jsf"> <level name="INFO"
/> </logger> -->
<!-- Limit JNP <logger category="org.jnp"> <level name="INFO" /> </logger> -->
<!-- Limit the JSR77 categories -->
<logger category="org.jboss.management">
<level name="INFO" />
</logger>
<!-- Limit the verbose facelets compiler -->
<!-- Also suppress error with legacy facelets (JBAS-7600) -->
<logger category="facelets.compiler">
<level name="WARN" />
<filter>
<not>
<match pattern="Error\sLoading\sLibrary.*jsf-libs/jsf-impl" />
</not>
</filter>
</logger>
<logger category="org.jboss.serial">
<level name="INFO" />
</logger>
<!-- Reduce org.mc4j stuff in the logs -->
<logger category="org.mc4j">
<level name="WARN" />
</logger>
<logger category="org.rhq.plugins.jbossas5.ApplicationServerComponent">
<level name="FATAL" />
</logger>
<!-- ======================= -->
<!-- Setup the Root category -->
<!-- ======================= -->
<root-logger>
<!-- Set the root logger priority via a system property, with a default
value. -->
<level name="${jboss.server.log.threshold:DEBUG}" />
<handlers>
<handler-ref name="MERCURIUS" />
</handlers>
</root-logger>
</logging>
{code}
Since I use the /server/default/ configuration, I changed the logmanager-jboss-beans.xml in the /server/default/deployers/jboss-logging.deployer/META-INF directory. These are the lines relative to the per classloader context selector. I have added a link in the comment relative to the known problem:
{code:xml}
<!--
~ These two beans define the per-classloader log context selector which allows per-deployment logging. Since
~ enabling this feature may have a performance impact in certain cases, it's started up lazily (on demand)
~ when a separate log context is defined in a user deployment.
-->
<!-- @Pasquale: modified according to https://issues.jboss.org/browse/JBAS-9407 -->
<!-- Workaround for JBoss Logging bug http://community.jboss.org/message/587287#587287 -->
<bean name="JBossLogManagerContextSelectorService" class="org.jboss.logmanager.ClassLoaderLogContextSelector"/>
<bean name="OnDemandJBossLogManagerContextSelectorService" class="org.jboss.logmanager.LogContextSelectorService">
<property name="selector">
<inject bean="JBossLogManagerContextSelectorService"/>
</property>
</bean>
{code}
The classes I deploy on the AS refer to the JBoss Logger. For instance, my Helper.java uses Logger like this:
{code:java}
import org.jboss.logging.Logger;
private static final Logger log = Logger.getLogger(Helper.class);
{code}
You'll probably get a NPE when stopping your AS, read here:
Comments