|
| 1 | +//// |
| 2 | + Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + contributor license agreements. See the NOTICE file distributed with |
| 4 | + this work for additional information regarding copyright ownership. |
| 5 | + The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + (the "License"); you may not use this file except in compliance with |
| 7 | + the License. You may obtain a copy of the License at |
| 8 | + |
| 9 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + |
| 11 | + Unless required by applicable law or agreed to in writing, software |
| 12 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + See the License for the specific language governing permissions and |
| 15 | + limitations under the License. |
| 16 | +//// |
| 17 | +
|
| 18 | += Building GraalVM native images |
| 19 | +
|
| 20 | +Since version |
| 21 | +xref:release-notes.adoc#release-notes-2-25-0[`2.25.0`] |
| 22 | +both |
| 23 | +xref:manual/api.adoc[Log4j API] |
| 24 | +and |
| 25 | +xref:manual/implementation.adoc[its reference implementation] |
| 26 | +provide out-of-the-box support for creating native executables using |
| 27 | +https://www.graalvm.org/[GraalVM]. |
| 28 | +
|
| 29 | +This document complements the |
| 30 | +xref:manual/installation.adoc[Installation Guide] |
| 31 | +and provides additional details on the steps necessary to create native images that use the Log4j API. |
| 32 | +The information is split depending on which Log4j API implementation you are using. |
| 33 | +
|
| 34 | +.Struggling with the logging API, implementation, and bridge concepts? Click for an introduction. |
| 35 | +[%collapsible] |
| 36 | +==== |
| 37 | +include::partial$concepts.adoc[tag=!software-type] |
| 38 | +==== |
| 39 | +
|
| 40 | +[TIP] |
| 41 | +==== |
| 42 | +Are you looking for an example of GraalVM application that uses the Log4j API? |
| 43 | +Check out |
| 44 | +the https://github.com/apache/logging-log4j-samples/tree/main/log4j-samples-graalvm[`log4j-samples-graalvm`] |
| 45 | +project. |
| 46 | +==== |
| 47 | +
|
| 48 | +[#impl-simple] |
| 49 | +== Using Simple Logger |
| 50 | +
|
| 51 | +If you use |
| 52 | +xref:manual/simple-logger.adoc[Simple Logger] shipped with xref:manual/api.adoc[Log4j API] |
| 53 | +in your application, no additional steps are required to compile a GraalVM native image. |
| 54 | +
|
| 55 | +[#impl-core] |
| 56 | +== Using Log4j Core |
| 57 | +
|
| 58 | +Since version |
| 59 | +xref:release-notes.adoc#release-notes-2-25-0[`2.25.0`], |
| 60 | +xref:manual/implementation.adoc[Log4j Core] |
| 61 | +and |
| 62 | +xref:components.adoc[all its official extensions] |
| 63 | +are bundled with the necessary |
| 64 | +https://www.graalvm.org/latest/reference-manual/native-image/metadata/[GraalVM reachability metadata] |
| 65 | +to help GraalVM with the creation of native images. |
| 66 | +Additional steps are only required: |
| 67 | +
|
| 68 | +* If you use a configuration file, which is not in a |
| 69 | +xref:manual/configuration.adoc#automatic-configuration[standard location], you need to create a |
| 70 | +https://www.graalvm.org/jdk17/reference-manual/native-image/metadata/#resource-metadata-in-json[`META-INF/native-image/<groupId>/<artifactId>/resource-config.json`] file in your classpath with content: |
| 71 | ++ |
| 72 | +[source,json] |
| 73 | +---- |
| 74 | +{ |
| 75 | + "resources": { |
| 76 | + "includes": [ |
| 77 | + { |
| 78 | + "pattern": "path/to/your/configuration/file" |
| 79 | + } |
| 80 | + ] |
| 81 | + } |
| 82 | +} |
| 83 | +---- |
| 84 | +
|
| 85 | +* If you use **third-party** |
| 86 | +xref:manual/plugins.adoc[Log4j Plugin JARs] |
| 87 | +you need to make sure they contain a |
| 88 | +https://www.graalvm.org/jdk17/reference-manual/native-image/metadata/#specifying-reflection-metadata-in-json[`reflect-config.json`] metadata file. |
| 89 | +If that is not the case, please point the maintainer to the |
| 90 | +xref:manual/plugins.adoc#plugin-registry[Log4j Plugin registration documentation]. |
| 91 | +
|
| 92 | +[#impl-jul] |
| 93 | +== Using JUL |
| 94 | +
|
| 95 | +Since version `2.24.0` the |
| 96 | +xref:manual/installation.adoc#impl-jul[Log4j API to JUL bridge] |
| 97 | +is tested for compatibility with GraalVM. |
| 98 | +
|
| 99 | +Although `java.util.logging` is embedded into the JRE, currently not all |
| 100 | +https://docs.oracle.com/en/java/javase/17/docs/api/java.logging/java/util/logging/Formatter.html[`j.u.l.Formatter`] |
| 101 | +and |
| 102 | +https://docs.oracle.com/en/java/javase/17/docs/api/java.logging/java/util/logging/Handler.html[`j.u.l.Handler`] |
| 103 | +implementations have the required GraalVM metadata. |
| 104 | +See the official |
| 105 | +https://www.graalvm.org/latest/reference-manual/native-image/guides/add-logging-to-native-executable/[Add Logging to a Native Executable] |
| 106 | +guide for more information on how to add additional elements to your configuration. |
| 107 | +
|
| 108 | +[TIP] |
| 109 | +==== |
| 110 | +See |
| 111 | +https://github.com/apache/logging-log4j-samples/blob/main/log4j-samples-graalvm/src/reachability-metadata/jul/reflect-config.json[`reflect-config.json` in our `log4j-samples-graalvm` example project] |
| 112 | +for an example on how to enable `j.u.l.FileHandler`. |
| 113 | +==== |
| 114 | +
|
| 115 | +[#impl-logback] |
| 116 | +== Using Logback |
| 117 | +
|
| 118 | +Since version `2.24.0` the |
| 119 | +xref:manual/installation.adoc#impl-logback[Log4j API to SLF4J bridge] |
| 120 | +is tested for compatibility with GraalVM. |
| 121 | +
|
| 122 | +While Logback itself does not provide any GraalVM metadata, the data is available in the third-party |
| 123 | +https://github.com/oracle/graalvm-reachability-metadata/[GraalVM reachability metadata repository]. |
| 124 | +
|
| 125 | +See the GraalVM Reachability Metadata Support documentation appropriate for your build tool for more information: |
| 126 | +
|
| 127 | +* https://graalvm.github.io/native-build-tools/latest/gradle-plugin.html#metadata-support[Gradle Plugin documentation] |
| 128 | +* https://graalvm.github.io/native-build-tools/latest/maven-plugin.html#metadata-support[Maven Plugin documentation] |
0 commit comments