Skip to content

Commit

Permalink
Use log4j2 in Scalar DB server (#358)
Browse files Browse the repository at this point in the history
  • Loading branch information
brfrn169 committed Oct 31, 2021
1 parent 1ebd9e3 commit 1aa9adb
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 14 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ subprojects {
spotbugsVersion = '4.3.0'
errorproneVersion = '2.8.0'
errorproneJavacVersion = '9+181-r4173-1'
log4jVersion = '2.14.1'
}

repositories {
Expand Down
6 changes: 3 additions & 3 deletions server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ WORKDIR /scalardb

# The path should be relative from build/docker. Running `gradle docker`
# (provided by com.palantir.docker plugin) will copy this Dockerfile and
# server.tar and log4j.properties to build/docker.
# server.tar and log4j2.properties to build/docker.
ADD server.tar .

WORKDIR /scalardb/server

COPY log4j.properties .
COPY log4j2.properties .

ENV SCALARDB_SERVER_OPTS -Dlog4j.configuration=file:log4j.properties
ENV SCALARDB_SERVER_OPTS -Dlog4j.configurationFile=file:log4j2.properties

ENTRYPOINT ["./bin/scalardb-server"]
CMD ["--config", "database.properties"]
Expand Down
11 changes: 9 additions & 2 deletions server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This runs Scalar DB Server:

```
$ cd server/build/install/server
$ export SCALARDB_SERVER_OPTS="<your JVM options>"
$ bin/scalardb-server --config <your configuration file path>
```

Expand All @@ -32,8 +33,14 @@ $ ./gradlew docker
This runs the Scalar DB Server (you need to specify your local configuration file path with `-v` flag):

```
$ docker run -v <your local configuration file path>:/scalardb/server/database.properties -d ghcr.io/scalar-labs/scalardb-server:<version>
$ docker run -v <your local configuration file path>:/scalardb/server/database.properties -d -p 60051:60051 -p 8080:8080 ghcr.io/scalar-labs/scalardb-server:<version>
# For DEBUG logging
$ docker run -v <your local configuration file path>:/scalardb/server/database.properties -e JAVA_OPTS=-Dlog4j.logLevel=DEBUG -d ghcr.io/scalar-labs/scalardb-server:<version>
$ docker run -v <your local configuration file path>:/scalardb/server/database.properties -e JAVA_OPTS=-Dlog4j.logLevel=DEBUG -d -p 60051:60051 -p 8080:8080 ghcr.io/scalar-labs/scalardb-server:<version>
# For custom log configuration
$ docker run -v <your local configuration file path>:/scalardb/server/database.properties -v <your custom log4j2 configuration file path>:/scalardb/server/log4j2.properties -d -p 60051:60051 -p 8080:8080 ghcr.io/scalar-labs/scalardb-server:<version>
# For JMX
$ docker run -v <your local configuration file path>:/scalardb/server/database.properties -e JAVA_OPTS="-Djava.rmi.server.hostname=<your container hostname or IP address> -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.port=9990 -Dcom.sun.management.jmxremote.rmi.port=9990 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false" -d -p 60051:60051 -p 8080:8080 -p 9990:9990 ghcr.io/scalar-labs/scalardb-server:<version>
```
6 changes: 4 additions & 2 deletions server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ dependencies {
implementation group: 'com.google.guava', name: 'guava', version: "${guavaVersion}"
implementation group: 'com.google.inject', name: 'guice', version: "${guiceVersion}"
implementation group: 'org.slf4j', name: 'slf4j-api', version: "${slf4jVersion}"
implementation group: 'org.slf4j', name: 'slf4j-log4j12', version: "${slf4jVersion}"
implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: "${log4jVersion}"
implementation group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: "${log4jVersion}"
implementation group: 'com.google.protobuf', name: 'protobuf-java-util', version: "${protobufVersion}"
implementation group: 'info.picocli', name: 'picocli', version: "${picoCliVersion}"
implementation(group: 'com.scalar-labs', name: 'scalar-admin', version: "${scalarAdminVersion}") {
exclude group: 'io.grpc'
exclude group: 'org.slf4j'
}
implementation group: 'io.dropwizard.metrics', name: 'metrics-core', version: "${dropwizardMetricsVersion}"
implementation group: 'io.dropwizard.metrics', name: 'metrics-jmx', version: "${dropwizardMetricsVersion}"
Expand All @@ -59,7 +61,7 @@ application {

docker {
name "ghcr.io/scalar-labs/scalardb-server:${project.version}"
files tasks.distTar.outputs, 'conf/log4j.properties'
files tasks.distTar.outputs, 'conf/log4j2.properties'
}

task integrationTestScalarDbServer(type: Test) {
Expand Down
7 changes: 0 additions & 7 deletions server/conf/log4j.properties

This file was deleted.

6 changes: 6 additions & 0 deletions server/conf/log4j2.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
rootLogger.level=${sys:log4j.logLevel:-INFO}
rootLogger.appenderRef.stdout.ref=STDOUT
appender.console.type=Console
appender.console.name=STDOUT
appender.console.layout.type=PatternLayout
appender.console.layout.pattern=%d [%-5p %c] %m%n

0 comments on commit 1aa9adb

Please sign in to comment.