Skip to content

Commit

Permalink
Add log4j logging (#383)
Browse files Browse the repository at this point in the history
Enables java logging. The log level can be changed by setting a variable.
Set and run like this:

export JAVA_OPTS="-Dorg.metafacture.metafix.logLevel=DEBUG"; ./gradlew installDist;  cd metafix-runner/build/install/metafix-runner; bin/metafix-runner $pathTo.flux

Note that you cannot use `./gradlew :metafix-runner:run ...` as setting
the log level only works within the distribution.

Co-authored-by: Jens Wille <jens.wille@hbz-nrw.de>
  • Loading branch information
dr0i and blackwinter committed Nov 29, 2024
1 parent 93afd59 commit c5aacab
Showing 3 changed files with 29 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -28,6 +28,12 @@ To execute a Fix (embedded in a Flux) via CLI:

`./gradlew :metafix-runner:run --args="$PWD/path/to.flux"`

To execute a Fix (embedded in a Flux) via CLI in java debug mode:
make sure to pipe to `log-stream` after your `fix` command in flux resp. make
use of `log-object` at the proper location. Then:

`export JAVA_OPTS="-Dorg.metafacture.metafix.logLevel=DEBUG"; ./gradlew installDist; cd metafix-runner/build/install/metafix-runner; bin/metafix-runner "$PWD/path/to.flux"`

(To import the projects in Eclipse, choose `File > Import > Existing Gradle Project` and select the `metafacture-fix` directory.)

## Usage
6 changes: 5 additions & 1 deletion metafix-runner/build.gradle
Original file line number Diff line number Diff line change
@@ -39,11 +39,15 @@ dependencies {
application {
mainClass = 'org.metafacture.runner.Flux'

applicationDefaultJvmArgs = [
"-Dorg.metafacture.metafix.logLevel=INFO"
]

if (project.hasProperty('profile')) {
def file = project.getProperty('profile') ?: project.name
def depth = project.hasProperty('profile.depth') ? project.getProperty('profile.depth') : 8

applicationDefaultJvmArgs = [
applicationDefaultJvmArgs += [
"-XX:FlightRecorderOptions=stackdepth=${depth}",
"-XX:StartFlightRecording=dumponexit=true,filename=${file}.jfr,settings=profile"
]
18 changes: 18 additions & 0 deletions metafix/src/main/resources/log4j.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">

<log4j:configuration>
<appender name="stdout" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%-5p [%t] [%c{1}] %m%n" />
</layout>
</appender>

<root>
<priority value="${org.metafacture.metafix.logLevel}" />
<appender-ref ref="stdout" />
</root>

</log4j:configuration>

0 comments on commit c5aacab

Please sign in to comment.