Permalink
Browse files

- Added logger for log4j2

- Added log4j (2 JARs)
- JIRA: https://issues.jboss.org/browse/JGRP-1585
- Defined correct lib/* inclusion for JARs in ./lib dir
- Added config file for JUL logging
- log4j2.xml: added follow=true (to tweak stdout/stderr)
- JUnitXMLReporter: deleting old test directory before running new test
- Using String.format() instead of MessageFormat.format()
- Added vararg methods to Log
- Implementation of log impls (+vararg methods)
- Added support for log4j2 to LogFactory (prefers log4j2 over log4j over JUL)
- Set the dest in UNICAST_MessagesToSelfTest: before it was null, so we didn't really test unicast messages !
- Using runtest in build.xml
- Fixed incorrect path for byteman tests
- Documentation for logging
  • Loading branch information...
1 parent 49ba286 commit 9f2bb99efd0ba4d45feec2b1572a81b96c18bfb3 Bela Ban committed Mar 15, 2013
Showing with 644 additions and 243 deletions.
  1. +12 −7 bin/jgroups.sh
  2. +18 −35 build.xml
  3. +17 −17 conf/jg-messages.properties
  4. +17 −17 conf/jg-messages_de.properties
  5. +15 −0 conf/log4j2.xml
  6. +55 −0 conf/logging.properties
  7. +66 −0 doc/manual/en/modules/installation.xml
  8. +14 −0 lib/licenses/thirdparty-licenses.xml
  9. BIN lib/log4j-api-2.0-beta4.jar
  10. BIN lib/log4j-core-2.0-beta4.jar
  11. +1 −1 src/org/jgroups/blocks/TCPConnectionMap.java
  12. +3 −19 src/org/jgroups/conf/ClassConfigurator.java
  13. +1 −1 src/org/jgroups/conf/ConfiguratorFactory.java
  14. +1 −1 src/org/jgroups/conf/XmlConfigurator.java
  15. +4 −4 src/org/jgroups/jmx/ResourceDMBean.java
  16. +58 −13 src/org/jgroups/logging/JDKLogImpl.java
  17. +11 −0 src/org/jgroups/logging/Log.java
  18. +152 −0 src/org/jgroups/logging/Log4J2LogImpl.java
  19. +59 −13 src/org/jgroups/logging/Log4JLogImpl.java
  20. +50 −23 src/org/jgroups/logging/LogFactory.java
  21. +0 −2 src/org/jgroups/protocols/BPING.java
  22. +0 −1 src/org/jgroups/protocols/COUNTER.java
  23. +0 −2 src/org/jgroups/protocols/RSVP.java
  24. +0 −1 src/org/jgroups/protocols/STOMP.java
  25. +7 −3 src/org/jgroups/protocols/TP.java
  26. +20 −22 src/org/jgroups/protocols/UDP.java
  27. +5 −5 src/org/jgroups/protocols/UNICAST.java
  28. +2 −6 src/org/jgroups/protocols/UNICAST3.java
  29. +1 −1 src/org/jgroups/protocols/pbcast/GMS.java
  30. +1 −1 src/org/jgroups/protocols/pbcast/NAKACK.java
  31. +2 −2 src/org/jgroups/protocols/pbcast/NAKACK2.java
  32. +0 −2 src/org/jgroups/protocols/tom/TOA.java
  33. +7 −7 src/org/jgroups/stack/Configurator.java
  34. +1 −1 src/org/jgroups/stack/IpAddress.java
  35. +2 −4 src/org/jgroups/util/SuppressLog.java
  36. +1 −11 src/org/jgroups/util/Util.java
  37. +32 −6 tests/junit-functional/org/jgroups/protocols/UNICAST_MessagesToSelfTest.java
  38. +2 −7 tests/junit-functional/org/jgroups/tests/LargeMergeTest.java
  39. +7 −8 tests/util/org/jgroups/util/JUnitXMLReporter.java
View
@@ -13,17 +13,22 @@ if [ ! -d $LIB ]; then
LIB=$JG
fi;
-for i in $LIB/*.jar
-do
- CP=$CP:$i
-done
+CP=$CP:$LIB/*
if [ -f $HOME/log4j.properties ]; then
LOG="-Dlog4j.configuration=file:$HOME/log4j.properties"
fi;
-JG_FLAGS="-Dresolve.dns=false -Djgroups.bind_addr=$IP_ADDR -Djboss.tcpping.initial_hosts=$IP_ADDR[7800]"
-JG_FLAGS="$JG_FLAGS -Djava.net.preferIPv4Stack=true -Djgroups.timer.num_threads=4"
+if [ -f $HOME/log4j2.xml ]; then
+ LOG="$LOG -Dlog4j.configurationFile=$HOME/log4j2.xml"
+fi;
+
+if [ -f $HOME/logging.properties ]; then
+ LOG="$LOG -Djava.util.logging.config.file=$HOME/logging.properties"
+fi;
+
+JG_FLAGS="-Djgroups.bind_addr=$IP_ADDR -Djboss.tcpping.initial_hosts=$IP_ADDR[7800]"
+JG_FLAGS="$JG_FLAGS -Djava.net.preferIPv4Stack=true"
FLAGS="-server -Xmx600M -Xms600M"
FLAGS="$FLAGS -XX:CompileThreshold=10000 -XX:+AggressiveHeap -XX:ThreadStackSize=64K -XX:SurvivorRatio=8"
FLAGS="$FLAGS -XX:TargetSurvivorRatio=90 -XX:MaxTenuringThreshold=31"
@@ -42,5 +47,5 @@ EXPERIMENTAL="$EXPERIMENTAL -XX:+EliminateLocks -XX:+UseBiasedLocking"
#DEBUG="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5000"
-java -classpath $CP $DEBUG $LOG $JG_FLAGS $FLAGS $EXPERIMENTAL $JMX $*
+java -cp $CP $DEBUG $LOG $JG_FLAGS $FLAGS $EXPERIMENTAL $JMX $*
View
@@ -388,48 +388,29 @@
<target name="functional" depends="postcompile">
<mkdir dir="${tmp.dir}/test-results/xml/functional"/>
- <testng classpathref="jg.classpath"
- usedefaultlisteners="false"
- outputdir="${tmp.dir}/test-results/xml"
- listeners="org.jgroups.util.JUnitXMLReporter"
- threadcount="10"
- parallel="methods"
- >
- <jvmarg value="-Djava.net.preferIPv4Stack=${java.net.preferIPv4Stack}"/>
- <jvmarg value="-Djava.net.preferIPv6Addresses=${java.net.preferIPv6Addresses}"/>
- <xmlfileset dir="${testng.conf.dir}" includes="functional.xml"/>
- </testng>
+ <runtest testname.ext="functional"
+ threadcount="10"
+ parallel="methods"
+ testng.xmlfile="functional.xml"/>
</target>
+
<target name="byteman" depends="postcompile">
<mkdir dir="${tmp.dir}/test-results/xml/byteman"/>
- <testng classpathref="jg.classpath.byteman"
- usedefaultlisteners="false"
- outputdir="${tmp.dir}/test-results/xml"
- listeners="org.jgroups.util.JUnitXMLReporter"
- threadcount="1"
- parallel="false"
- >
- <jvmarg value="-Djava.net.preferIPv4Stack=${java.net.preferIPv4Stack}"/>
- <jvmarg value="-Djava.net.preferIPv6Addresses=${java.net.preferIPv6Addresses}"/>
- <jvmarg value="-Djgroups.bind_addr=${jgroups.bind_addr}"/>
- <xmlfileset dir="${testng.conf.dir}" includes="byteman.xml"/>
- </testng>
+ <runtest classpath="jg.classpath.byteman"
+ testname.ext="byteman"
+ threadcount="1"
+ parallel="false"
+ testng.xmlfile="byteman.xml"/>
</target>
+
<target name="time-sensitive" depends="postcompile">
<mkdir dir="${tmp.dir}/test-results/xml/time-sensitive"/>
- <testng classpathref="jg.classpath"
- usedefaultlisteners="false"
- outputdir="${tmp.dir}/test-results/xml"
- listeners="org.jgroups.util.JUnitXMLReporter"
- threadcount="1"
- parallel="methods"
- >
- <jvmarg value="-Djava.net.preferIPv4Stack=${java.net.preferIPv4Stack}"/>
- <jvmarg value="-Djava.net.preferIPv6Addresses=${java.net.preferIPv6Addresses}"/>
- <xmlfileset dir="${testng.conf.dir}" includes="time-sensitive.xml"/>
- </testng>
+ <runtest testname.ext="sensitive"
+ threadcount="1"
+ parallel="methods"
+ testng.xmlfile="time-sensitive.xml"/>
</target>
<target name="stack-independent" depends="postcompile">
@@ -538,6 +519,7 @@
<macrodef name="runtest" description="Runs a configuration-dependent test suite">
+ <attribute name="classpath" default="jg.classpath"/>
<attribute name="outputdir" default="${tmp.dir}/test-results/xml"/>
<attribute name="parallel" default="methods"/>
<attribute name="testname.ext" default="udp"/>
@@ -549,7 +531,7 @@
<attribute name="tcp.recv.buf.size" default="200000"/>
<attribute name="tcp.send.buf.size" default="64000"/>
<sequential>
- <testng classpathref="jg.classpath"
+ <testng classpathref="@{classpath}"
usedefaultlisteners="false"
outputdir="@{outputdir}"
listeners="org.jgroups.util.JUnitXMLReporter"
@@ -568,6 +550,7 @@
<jvmarg value="-Djgroups.tunnel.gossip_router_hosts=${jgroups.tunnel.gossip_router_hosts}"/>
<jvmarg value="-Dtests.tmp.dir=${tmp.dir}"/>
<jvmarg value="-Dlog4j.configuration=file:${conf.dir}/log4j.properties"/>
+ <jvmarg value="-Dlog4j.configurationFile=${conf.dir}/log4j2.xml"/>
<jvmarg value="-Djava.net.preferIPv4Stack=${java.net.preferIPv4Stack}"/>
<jvmarg value="-Djava.net.preferIPv6Addresses=${java.net.preferIPv6Addresses}"/>
<jvmarg value="-Xms400M"/>
@@ -1,17 +1,17 @@
-ConfigurationError = [JGRP00001] configuration error: the following properties in {0} are not recognized: {1}
-ProtocolLoadError = [JGRP00002] unable to load protocol {0} (either with relative - {0} - or absolute - {1} - class name)
-FileNotFound = [JGRP00003] file \"{0}\" not found
-ParseError = [JGRP00004] parsing failure; the XML document is not correct: {0}
-ProtocolCreateError = [JGRP00005] failure creating protocol {0}: {1}
-AcceptError = [JGRP00006] failed accepting connection from peer: {0}
-AttrReadFailure = [JGRP00007] failed reading value of attribute {0}: {1}
-MissingAttribute = [JGRP00008] did not find attribute with name {0}
-AttrWriteFailure = [JGRP00009] failed writing to attribute {0}: {1}
-VersionMismatch = [JGRP00010] packet from {0} has different version ({1}) than ours ({2}); packet is discarded
-MsgDroppedNak = [JGRP00011] {0}: dropped message {1} from non-member {2} (view={3})
-MsgDroppedDiffCluster = [JGRP00012] discarded message from different cluster {0} (our cluster is {1}). Sender was {2}
-BatchDroppedDiffCluster = [JGRP00013] discarded message batch from different cluster {0} (our cluster is {1}). Sender was {2}
-SuppressMsg = (received {0} identical messages from {1} in the last {2} ms)
-Deprecated = [JGRP00014] {0} has been deprecated: {1}
-IncorrectBufferSize = [JGRP00015] the {0} buffer of socket {1} was set to {2}, but the OS only allocated {3}. \
- This might lead to performance problems. Please set your max {4} buffer in the OS correctly (e.g. {5} on Linux)
+ConfigurationError = [JGRP00001] configuration error: the following properties in %s are not recognized: %s
+ProtocolLoadError = [JGRP00002] unable to load protocol %1$s (either with relative - %1$s - or absolute - %2$s - class name)
+FileNotFound = [JGRP00003] file \"%s\" not found
+ParseError = [JGRP00004] parsing failure; the XML document is not correct: %s
+ProtocolCreateError = [JGRP00005] failure creating protocol %s: %s
+AcceptError = [JGRP00006] failed accepting connection from peer: %s
+AttrReadFailure = [JGRP00007] failed reading value of attribute %s: %s
+MissingAttribute = [JGRP00008] did not find attribute with name %s
+AttrWriteFailure = [JGRP00009] failed writing to attribute %s: %s
+VersionMismatch = [JGRP00010] packet from %s has different version (%s) than ours (%s); packet is discarded
+MsgDroppedNak = [JGRP00011] %s: dropped message %s from non-member %s (view=%s)
+MsgDroppedDiffCluster = [JGRP00012] discarded message from different cluster %s (our cluster is %s). Sender was %s
+BatchDroppedDiffCluster = [JGRP00013] discarded message batch from different cluster %s (our cluster is %s). Sender was %s
+SuppressMsg = (received %d identical messages from %s in the last %d ms)
+Deprecated = [JGRP00014] %s has been deprecated: %s
+IncorrectBufferSize = [JGRP00015] the %s buffer of socket %s was set to %s, but the OS only allocated %s. \
+ This might lead to performance problems. Please set your max %s buffer in the OS correctly (e.g. %s on Linux)
@@ -1,17 +1,17 @@
-ConfigurationError = [JGRP00001] Konfigurationsfehler: die folgenden Parameter in {0} sind nicht erlaubt: {1}
-ProtocolLoadError = [JGRP00002] Fehler beim Laden des Protokolls {0} (sowohl mit relativem - {0} - als auch absolutem - {1} - Pfadnamen)
-FileNotFound = [JGRP00003] Datei \"{0}\" nicht gefunden
-ParseError = [JGRP00004] Fehler beim Parsen von XML; das Dokument ist nicht korrekt: {0}
-ProtocolCreateError = [JGRP00005] Protokoll {0} konnte nicht instantiiert werden: {1}
-AcceptError = [JGRP00006] Verbindung vom Peer konnte nicht hergestellt werden: {0}
-AttrReadFailure = [JGRP00007] Attribut {0} konnte nicht gelesen werden: {1}
-MissingAttribute = [JGRP00008] Attribut {0} wurde nicht gefunden
-AttrWriteFailure = [JGRP00009] Attribut {0} konnte nicht geschrieben werden: {1}
-VersionMismatch = [JGRP00010] Nachricht von {0} hat eine andere Version ({1}) als unsere ({2}); Nachricht wird verworfen
-MsgDroppedNak = [JGRP00011] {0}: Nachricht {1} von Nicht-Mitglied {2} wurde verworfen (View={3})
-MsgDroppedDiffCluster = [JGRP00012] Nachricht von Cluster {0} wurde verworfen (unser Cluster ist {1}). Der Sender war {2}
-BatchDroppedDiffCluster = [JGRP00013] Nachrichten-Batch von Cluster {0} wurde verworfen (unser Cluster ist {1}). Der Sender war {2}
-SuppressMsg = ({0} identische Nachrichten erhalten von {1} in den letzten {2} ms)
-Deprecated = [JGRP00014] {0} wird nicht mehr unterstuetzt: {1}
-IncorrectBufferSize = [JGRP00015] Der {0} Puffer des Sockets {1} wurde auf {2} gesetzt, aber das Betriebssystem stellt nur {3} zur Verfuegung. \
- Dies koennte zu Performanzproblemen fuehren. Bitte setzen Sie den max {4} Puffer im Betriebssystem korrekt (z.B. {5} unter Linux)
+ConfigurationError = [JGRP00001] Konfigurationsfehler: die folgenden Parameter in %s sind nicht erlaubt: %s
+ProtocolLoadError = [JGRP00002] Fehler beim Laden des Protokolls %1$s (sowohl mit relativem - %1$s - als auch absolutem - %2$s - Pfadnamen)
+FileNotFound = [JGRP00003] Datei \"%s\" nicht gefunden
+ParseError = [JGRP00004] Fehler beim Parsen von XML; das Dokument ist nicht korrekt: %s
+ProtocolCreateError = [JGRP00005] Protokoll %s konnte nicht instantiiert werden: %s
+AcceptError = [JGRP00006] Verbindung vom Peer konnte nicht hergestellt werden: %s
+AttrReadFailure = [JGRP00007] Attribut %s konnte nicht gelesen werden: %s
+MissingAttribute = [JGRP00008] Attribut %s wurde nicht gefunden
+AttrWriteFailure = [JGRP00009] Attribut %s konnte nicht geschrieben werden: %s
+VersionMismatch = [JGRP00010] Nachricht von %s hat eine andere Version (%s) als unsere (%s); Nachricht wird verworfen
+MsgDroppedNak = [JGRP00011] %s: Nachricht %s von Nicht-Mitglied %s wurde verworfen (View=%s)
+MsgDroppedDiffCluster = [JGRP00012] Nachricht von Cluster %s wurde verworfen (unser Cluster ist %s). Der Sender war %s
+BatchDroppedDiffCluster = [JGRP00013] Nachrichten-Batch von Cluster %s wurde verworfen (unser Cluster ist %s). Der Sender war %s
+SuppressMsg = (%d identische Nachrichten erhalten von %s in den letzten %d ms)
+Deprecated = [JGRP00014] %s wird nicht mehr unterstuetzt: %s
+IncorrectBufferSize = [JGRP00015] Der %s Puffer des Sockets %s wurde auf %s gesetzt, aber das Betriebssystem stellt nur %s zur Verfuegung. \
+ Dies koennte zu Performanzproblemen fuehren. Bitte setzen Sie den max %s Puffer im Betriebssystem korrekt (z.B. %s unter Linux)
View
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration>
+ <appenders>
+ <Console name="STDOUT" target="SYSTEM_OUT" follow="true">
+ <!--PatternLayout pattern="%-7d{HH:mm:ss,SSS} [%p] %c: %m%n"/-->
+ <PatternLayout pattern="%r [%p] %c{1}: %m%n"/>
+ </Console>
+ </appenders>
+ <loggers>
+ <root level="warn">
+ <appender-ref ref="STDOUT"/>
+ </root>
+ <logger name="org.jgroups" level="warn"/>
+ </loggers>
+</configuration>
View
@@ -0,0 +1,55 @@
+############################################################
+# Default Logging Configuration File
+#
+# You can use a different file by specifying a filename
+# with the java.util.logging.config.file system property.
+# For example java -Djava.util.logging.config.file=myfile
+############################################################
+
+############################################################
+# Global properties
+############################################################
+
+# "handlers" specifies a comma separated list of log Handler
+# classes. These handlers will be installed during VM startup.
+# Note that these classes must be on the system classpath.
+# By default we only configure a ConsoleHandler, which will only
+# show messages at the INFO and above levels.
+handlers= java.util.logging.ConsoleHandler
+
+# To also add the FileHandler, use the following line instead.
+#handlers= java.util.logging.FileHandler, java.util.logging.ConsoleHandler
+
+# Default global logging level.
+# This specifies which kinds of events are logged across
+# all loggers. For any given facility this global level
+# can be overriden by a facility specific level
+# Note that the ConsoleHandler also has a separate level
+# setting to limit messages printed to the console.
+.level=WARNING
+
+############################################################
+# Handler specific properties.
+# Describes specific configuration info for Handlers.
+############################################################
+
+# default file output is in user's home directory.
+java.util.logging.FileHandler.pattern = %h/java%u.log
+java.util.logging.FileHandler.limit = 50000
+java.util.logging.FileHandler.count = 1
+java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter
+
+# Limit the message that are printed on the console to INFO and above.
+java.util.logging.ConsoleHandler.level = FINEST
+java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
+
+
+############################################################
+# Facility specific properties.
+# Provides extra control for each logger.
+############################################################
+
+# For example, set the com.xyz.foo logger to only log SEVERE
+# messages:
+org.jgroups = FINEST
+org.jgroups.handlers= java.util.logging.ConsoleHandler
@@ -33,6 +33,11 @@
unittests, then xalan.jar needs to be in the CLASSPATH (also
available in the lib directory)
</listitem>
+ <listitem>
+ Logging: by default, JGroups tries to use log4j2. If the classes are not found on the classpath, it
+ resorts to log4j, and if still not found, it falls back to the java.util.logging logger.
+ See <xref linkend="Logging"/> for details on log configuration.
+ </listitem>
</itemizedlist>
</section>
@@ -169,6 +174,67 @@
</orderedlist>
</section>
+ <section id="Logging">
+ <title>Logging</title>
+ <para>
+ JGroups has no runtime dependencies; all that's needed to use it is to have jgroups.jar on the classpath.
+ For logging, this means the JVM's logging (java.util.logging) is used.
+ </para>
+ <para>
+ However, JGroups can use any other logging framework. By default, log4j and log4j2 are supported if the
+ corresponding JARs are found on the classpath.
+ </para>
+
+ <section id="log4j2">
+ <title>log4j2</title>
+ <para>
+ To use (<ulink url="http://logging.apache.org/log4j/2.x/manual/index.html">log4j2</ulink>), the
+ API and CORE JARs have to be found on the classpath. There's an XML configuration for log4j2 in the
+ conf dir, which can be used e.g. via -Dlog4j.configurationFile=$JGROUPS/conf/log4j2.xml.
+ </para>
+ <para>
+ log4j2 is currently the preferred logging library used by JGroups, and will be used even if the log4j
+ JAR is also present on the classpath.
+ </para>
+ </section>
+ <section id="log4j">
+ <title>log4j</title>
+ <para>
+ To use (<ulink url="http://logging.apache.org/log4j/1.2">log4j</ulink>), the log4j JAR has to be found
+ on the classpath. Note though that if the log4j2 API and CORE JARs are found, then log4j2 will be used,
+ so those JARs will have to be removed if log4j is to be used. There's an XML configuration for log4j in
+ the conf dir, which can be used e.g. via -Dlog4j.configuration=file:$JGROUPS/conf/log4j.properties.
+ </para>
+ </section>
+ <section id="JUL">
+ <title>JDK logging (JUL)</title>
+ <para>
+ To force use of JDK logging, even if the log4j(2) JARs are present, -Djgroups.use.jdk_logger=true
+ can be used.
+ </para>
+ </section>
+ <section id="CustomLoggers">
+ <title>Support for custom logging frameworks</title>
+ <para>
+ JGroups allows custom loggers to be used instead of the ones supported by default. To do this, interface
+ CustomLogFactory has to be implemented:
+ </para>
+ <programlisting language="Java">
+public interface CustomLogFactory {
+ Log getLog(Class clazz);
+ Log getLog(String category);
+}
+ </programlisting>
+ <para>
+ The implementation needs to return an implementation of org.jgroups.logging.Log.
+ </para>
+ <para>
+ To force using the custom log implementation, the fully qualified classname of the custom log
+ factory has to be provided via -Djgroups.logging.log_factory_class=com.foo.MyCustomLogger.
+ </para>
+ </section>
+ </section>
+
<section id="TestingTheSetup">
<title>Testing your Setup</title>
@@ -73,6 +73,20 @@
description='Java logging framework (runtime)'>
<jar name='log4j.jar' />
</module>
+ <module name='log4j2-api'
+ licenseType='apache-2.0'
+ version='2.0.0.Beta4'
+ projectHome='http://logging.apache.org/log4j/2.x/'
+ description='Java logging framework (runtime)'>
+ <jar name='log4j-api-2.0-beta4.jar' />
+ </module>
+ <module name='log4j2-core'
+ licenseType='apache-2.0'
+ version='2.0.0.Beta4'
+ projectHome='http://logging.apache.org/log4j/2.x/'
+ description='Java logging framework (runtime)'>
+ <jar name='log4j-core-2.0-beta4.jar' />
+ </module>
<module name='serializer'
licenseType='apache-2.0'
version='1.6.5'
View
Binary file not shown.
Binary file not shown.
Oops, something went wrong.

0 comments on commit 9f2bb99

Please sign in to comment.