@@ -19,11 +19,11 @@ limitations under the License.
1919
2020This project shows how to generate a native image using GraalVM.
2121
22- In order to use it:
22+ To use it:
2323
24- . set the `JAVA_HOME` environment variable to the path of a GraalVM installation,
25- . set the current working directory to the folder containing this file,
26- . generate the artifact locally with:
24+ . Set the `JAVA_HOME` environment variable to the path of a GraalVM installation,
25+ . Set the current working directory to the folder containing this file,
26+ . Generate the artifact locally with:
2727+
2828[source,shell]
2929----
@@ -32,24 +32,42 @@ In order to use it:
3232+
3333where `<backend>` can be:
3434
35+ `simple`::
36+ This profile uses `SimpleLogger` as logging backend.
37+
38+ `jul`::
39+ This profile uses `java.util.logging` as logging backend.
40+
41+ `logback`::
42+ This profile uses Logback as logging backend.
43+
3544`log4j-core`::
3645This profile uses Log4j Core as logging backend with its out-of-the-box reachability metadata.
46+ It uses
47+ https://logging.apache.org/log4j/2.x/manual/pattern-layout.html[Pattern Layout]
48+ to format log events.
3749
3850`log4j-core-jtl`::
39- This profile uses Log4j Core as logging backend with the addition of JSON Template Layout.
51+ This profile uses Log4j Core as logging backend with its out-of-the-box reachability metadata.
52+ It uses
53+ https://logging.apache.org/log4j/2.x/manual/json-template-layout.html[JSON Template Layout]
54+ to format log events.
4055
56+ [#log4j-core-minimal]
4157`log4j-core-minimal`::
4258This profile uses Log4j Core a logging backend with an external reachability metadata source optimized for size.
59+ It uses
60+ https://logging.apache.org/log4j/2.x/manual/pattern-layout.html[Pattern Layout]
61+ to format log events.
4362
44- `logback`::
45- This profile uses Logback as logging backend.
46-
47- `jul`::
48- This profile uses `java.util.logging` as logging backend.
63+ [#log4j-core-jtl-minimal]
64+ `log4j-core-jtl-minimal`::
65+ This profile uses Log4j Core a logging backend with an external reachability metadata source optimized for size.
66+ It uses
67+ https://logging.apache.org/log4j/2.x/manual/json-template-layout.html[JSON Template Layout]
68+ to format log events.
4969
50- `simple`::
51- This profile uses `SimpleLogger` as logging backend.
52- . run the application with
70+ . Run the application with
5371+
5472[source,shell]
5573----
@@ -58,10 +76,9 @@ target/log4j-samples-graalvm
5876
5977== Reachability metadata
6078
61- Log4j as many other Java libraries, relies heavily on reflection to convert the configuration file into an instance of a
79+ Log4j, as many other Java libraries, relies heavily on reflection to convert the configuration file into an instance of a
6280https://logging.apache.org/log4j/2.x/javadoc/log4j-core/org/apache/logging/log4j/core/config/Configuration.html[Configuration]
6381object.
64-
6582The classes that are accessed through reflection are called Log4j plugins and GraalVM must be aware of their existence through the usage of reachability metadata.
6683
6784See
7087https://www.graalvm.org/latest/reference-manual/native-image/metadata/[GraalVM reachability metadata]
7188for more details.
7289
73- The reachability metadata in this project was:
74-
75- * generated using the
76- https://www.graalvm.org/latest/reference-manual/native-image/metadata/AutomaticMetadataCollection/#tracing-agent[GraalVM tracing agent]:
77- +
78- [source,shell,subs=+attributes]
79- ----
80- # Build application classpath
81- export CLASSPATH=$(\
82- ../mvnw -q \
83- dependency:build-classpath -DincludeScope=runtime -Dmdep.outputProperty=classpath \
84- help:evaluate -Dexpression=classpath -DforceStdout \
85- )
86- CLASSPATH="target/log4j-samples-graalvm-0.0.0-SNAPSHOT.jar:$CLASSPATH"
87- # Run application using the GraalVM agent
88- $JAVA_HOME/bin/java \
89- -agentlib:native-image-agent=config-output-dir=src/reachability-metadata/minimal/log4j-core/2.24.0 \
90- org.apache.logging.log4j.samples.graalvm.Main
91- ----
92-
93- * the generated `reflect-config.json` file was further trimmed down manually, by removing all the Log4j plugins that are not used by this configuration.
94- These plugins are easy to spot, because they only have a `name` key.
90+ The
91+ https://logging.apache.org/log4j/2.x/manual/plugins.html#plugin-registry[Log4j plugin descriptors]
92+ and
93+ GraalVM reachability metadata used in the customized
94+ <<log4j-core-minimal,`use-log4j-core-minimal`>>
95+ and
96+ <<log4j-core-jtl-minimal,`use-log4j-core-jtl-minimal`>>
97+ profiles were generated using the procedure described in the documentation of the
98+ https://logging.apache.org/log4j/transform/cli.html#log4j-converter-plugin-descriptor[`log4j-converter-plugin-descriptor` tool].
9599
96100== Native binary size
97101
@@ -104,25 +108,29 @@ Since this is a trivial Java application, the difference between the binary size
104108In a typical application, those classes are already required, so the difference should be smaller.
105109====
106110
107- [cols="1 ,1"]
111+ [cols="3 ,1"]
108112|===
109113| Configuration | Size
110114
115+ | With `SimpleLogger`
116+ | 13.90 MiB
117+
118+ | With `java.util.logging`
119+ | 14.10 MiB
120+
121+ | With Logback
122+ | 30.62 MiB
123+
111124| With Log4j Core (manually optimized reachability metadata)
112125| 36.19 MiB
113126
127+ | With Log4j Core + JSON Template Layout (manually optimized reachability metadata)
128+ | 37.40 MiB
129+
114130| With Log4j Core (embedded full reachability metadata)
115131| 46.80 MiB
116132
117133| With Log4j Core + JSON Template Layout (embedded full reachability metadata)
118134| 47.37 MiB
119135
120- | With Logback
121- | 30.62 MiB
122-
123- | With `java.util.logging`
124- | 14.10 MiB
125-
126- | With `SimpleLogger`
127- | 13.90 MiB
128136|===
0 commit comments