Add log4j2 hooks to standard java logging

This commit is contained in:
Charles Allen 2015-02-19 10:29:54 -08:00
parent 49eae0fb70
commit edfcea18d8
4 changed files with 32 additions and 1 deletions

View File

@ -129,6 +129,14 @@
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jul</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</dependency>
<!-- com.lmax.disruptor is optional in log4j-core, so we explicitly include it here -->
<dependency>
<groupId>com.lmax</groupId>

View File

@ -8,11 +8,12 @@ This describes the common configuration shared by all Druid nodes. These configu
## JVM Configuration Best Practices
There are three JVM parameters that we set on all of our processes:
There are four JVM parameters that we set on all of our processes:
1. `-Duser.timezone=UTC` This sets the default timezone of the JVM to UTC. We always set this and do not test with other default timezones, so local timezones might work, but they also might uncover weird and interesting bugs.
2. `-Dfile.encoding=UTF-8` This is similar to timezone, we test assuming UTF-8. Local encodings might work, but they also might result in weird and interesting bugs.
3. `-Djava.io.tmpdir=<a path>` Various parts of the system that interact with the file system do it via temporary files, and these files can get somewhat large. Many production systems are set up to have small (but fast) `/tmp` directories, which can be problematic with Druid so we recommend pointing the JVMs tmp directory to something with a little more meat.
4. `-Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager` This allows log4j2 to handle logs for non-log4j2 components (like jetty) which use standard java logging.
### Extensions

View File

@ -17,6 +17,8 @@ java -Xmx512m -Duser.timezone=UTC -Dfile.encoding=UTF-8 \
Note the "-classpath" in this example has the config dir before the jars under lib/*.
To enable java logging to go through log4j2, set the `-Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager` server parameter.
An example log4j2.xml ships with Druid under config/_common/log4j2.xml, and a sample file is also shown below:
```

20
pom.xml
View File

@ -72,6 +72,7 @@
<druid.api.version>0.3.4</druid.api.version>
<jackson.version>2.4.4</jackson.version>
<log4j.version>2.1</log4j.version>
<slf4j.version>1.7.10</slf4j.version>
</properties>
<modules>
@ -396,6 +397,25 @@
<artifactId>log4j-1.2-api</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<!-- This is not slf4j's version because of performance concerns
http://www.slf4j.org/api/org/slf4j/bridge/SLF4JBridgeHandler.html
Please make sure to do performance tests before switching this to slf4j
Users wishing to use slf4j's solution are encouraged to also use
Logback
More info at
http://logback.qos.ch/manual/configuration.html#LevelChangePropagator
http://www.slf4j.org/legacy.html#jul-to-slf4j
-->
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jul</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>com.lmax</groupId>
<artifactId>disruptor</artifactId>