Skip to content

Commit

Permalink
chore: Provide logback native-image metadata out of the box (#32327)
Browse files Browse the repository at this point in the history
  • Loading branch information
johanandren authored Feb 26, 2024
1 parent 98d6c48 commit adda9b4
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 77 deletions.
10 changes: 7 additions & 3 deletions akka-docs/src/main/paradox/additional/native-image.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,12 @@ When using `akka-slf4j` for logging, automatically used for `akka-actor-typed`,
chosen needs extra configuration.

While Akka does not mandate a logger implementation, `logback-classic` is used in many Akka samples throughout the Akka projects.
Building native images with logback requires additional reflect entries, configuring static initialization of logback and either avoiding using
`ch.qos.logback.classic.AsyncAppender` or declaring your own lazy version of the appender (not starting any threads at native image build time).
Because of this Akka provides reflection metadata for logback out of the box, however projects using it will need an extra
native image flag `--initialize-at-build-time=ch.qos.logback`.

FIXME maybe just provide the lazy appender out of the box as well?
alternatively should we provide a lazy async logger appender or show it here?

If using `ch.qos.logback.classic.AsyncAppender` you will need to declare your own lazy version of the appender (not starting any threads at native image build time).

FIXME should we add link to working sample/config for logback?
FIXME should we provide a lazy async logger appender or show it here?
Original file line number Diff line number Diff line change
@@ -1,65 +1,79 @@
[
{
"condition" : { "typeReachable" : "ch.qos.logback.classic.Logger" },
"name":"ch.qos.logback.classic.encoder.PatternLayoutEncoder",
"queryAllPublicMethods":true,
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"condition" : { "typeReachable" : "ch.qos.logback.classic.Logger" },
"name":"ch.qos.logback.classic.pattern.DateConverter",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"condition" : { "typeReachable" : "ch.qos.logback.classic.Logger" },
"name":"ch.qos.logback.classic.pattern.LevelConverter",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"condition" : { "typeReachable" : "ch.qos.logback.classic.Logger" },
"name":"ch.qos.logback.classic.pattern.LineSeparatorConverter",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"condition" : { "typeReachable" : "ch.qos.logback.classic.Logger" },
"name":"ch.qos.logback.classic.pattern.LoggerConverter",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"condition" : { "typeReachable" : "ch.qos.logback.classic.Logger" },
"name":"ch.qos.logback.classic.pattern.MDCConverter",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"condition" : { "typeReachable" : "ch.qos.logback.classic.Logger" },
"name":"ch.qos.logback.classic.pattern.MarkerConverter",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"condition" : { "typeReachable" : "ch.qos.logback.classic.Logger" },
"name":"ch.qos.logback.classic.pattern.MessageConverter",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"condition" : { "typeReachable" : "ch.qos.logback.classic.Logger" },
"name":"ch.qos.logback.classic.pattern.ThreadConverter",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"condition" : { "typeReachable" : "ch.qos.logback.classic.Logger" },
"name":"ch.qos.logback.core.ConsoleAppender",
"queryAllPublicMethods":true,
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"condition" : { "typeReachable" : "ch.qos.logback.classic.Logger" },
"name":"ch.qos.logback.core.OutputStreamAppender",
"methods":[{"name":"setEncoder","parameterTypes":["ch.qos.logback.core.encoder.Encoder"] }]
},
{
"condition" : { "typeReachable" : "ch.qos.logback.classic.Logger" },
"name":"ch.qos.logback.core.encoder.Encoder",
"methods":[{"name":"valueOf","parameterTypes":["java.lang.String"] }]
},
{
"condition" : { "typeReachable" : "ch.qos.logback.classic.Logger" },
"name":"ch.qos.logback.core.encoder.LayoutWrappingEncoder",
"methods":[{"name":"setParent","parameterTypes":["ch.qos.logback.core.spi.ContextAware"] }]
},
{
"condition" : { "typeReachable" : "ch.qos.logback.classic.Logger" },
"name":"ch.qos.logback.core.pattern.PatternLayoutEncoderBase",
"methods":[{"name":"setPattern","parameterTypes":["java.lang.String"] }]
},
{
"condition" : { "typeReachable" : "ch.qos.logback.classic.Logger" },
"name":"ch.qos.logback.core.spi.ContextAware",
"methods":[{"name":"valueOf","parameterTypes":["java.lang.String"] }]
}

]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Args = --initialize-at-build-time=org.slf4j.LoggerFactory,org.slf4j.impl.StaticLoggerBinder,org.slf4j.MDC
6 changes: 5 additions & 1 deletion native-image-tests/cluster-scala/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ fork := true
enablePlugins(NativeImagePlugin)
nativeImageJvm := "graalvm-community"
nativeImageVersion := "21.0.2"
nativeImageOptions := Seq("--no-fallback", "--verbose", "-Dakka.native-image.debug=true")
nativeImageOptions := Seq(
"--no-fallback",
"--verbose",
"-Dakka.native-image.debug=true",
"--initialize-at-build-time=ch.qos.logback")

libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor-typed" % akkaVersion,
Expand Down

This file was deleted.

This file was deleted.

4 changes: 1 addition & 3 deletions native-image-tests/local-scala/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ fork := true
enablePlugins(NativeImagePlugin)
nativeImageJvm := "graalvm-community"
nativeImageVersion := "21.0.2"
nativeImageOptions := Seq(
"--no-fallback",
"--verbose")
nativeImageOptions := Seq("--no-fallback", "--verbose", "--initialize-at-build-time=ch.qos.logback")

libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor-typed" % akkaVersion,
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit adda9b4

Please sign in to comment.