Enable logback in JBoss
About 10 years ago log4j was the logging framework for java. Years passed and many logging frameworks emerged. For many people, including myself, logback is the new log4j (and that is not only because of Ceki).
Unfortunately it is not possible to run logback as slf4j implementation OOTB in JBoss like in Tomcat. The following 5 steps explain you how to get it running.
Please note: this guide is for JBoss Wildfly. Other versions may differ.
Step1: Set slf4j as logging provider in standalone.xml
Add following block right after *extensions *in your standalone.xml.
Step2: Install or create logback module
To enable logback, you’ll need a module. This is pretty straightforward. First create a new directory in your JBoss:
mkdir $JBOSS_HOME/modules/system/layers/base/ch/qos/logback/main
put your logback implementation into the folder, in my case: logback-classic-1.1.1.jar and *logback-core-1.1.1.jar. *Now create a file named module.xml and put following content into it:
Keep attention, that the version numbers in the filename and module definitions are the same.
Step3: Tell JBoss to use slf4j and logback for logging
Open $JBOSS_HOME/modules/system/layers/base/org/jboss/logging/main/module.xml
Remove dependency to *org.jboss.logmanager *and add dependencies to *logback and slf4j *instead. The resulting dependencies section should look like this:
Step4: Add logback.xml
You need to add *logback.xml. *A good place is $JBOSS_HOME/standalone/configuration. Of course it would be better to have it in the project, but JBoss does weird things to the contents of the project, and you might want to edit the configuration at runtime. For development environment you may want to link it to your source code location.
Tell logback where to look for the log files via VM Property in standalone.sh
export JBOSS_PATH=path-to-my-jboss-installation
export JAVA_OPTS="$JAVA_OPTS -DJBOSS_LOG_DIR=$JBOSS_PATH/standalone/log"
export JAVA_OPTS="$JAVA_OPTS -Dlogback.configurationFile=$JBOSS_PATH/standalone/configuration/logback.xml"
Sidestep: it is convenient to define the logfile location based on JBOSS_HOME in your logback.xml:
${JBOSS_HOME}/standalone/log/mylogfile.log
INFO
${JBOSS_HOME}/standalone/log/mylogfile.%i.log
1
5
100MB
%r %d{ISO8601} %m%n
Step5: Set logback as slf4j implementation.
JBoss comes with its own slf4j implementation which is … well, you don’t want it. To enable logback as slf4j implementation edit $JBOSS_HOME/modules/system/layers/base/org/slf4j/main/module.xml and set:
This is it.
Enjoy 😉
The Road to IntelliJ IDEA
When it comes to choosing an IDE for Java development, people usually face a challenge of having to pick one from the three main players: IntelliJ IDEA, Eclipse or NetBeans. The...
Connect Moskito-Central to MongoDB
Today we are going to connect MoSKito-Central to MongoDB database. In a few words, MoSKito-Central is a service ( remote or embedded ) that receives your MoSKito statistics and...
