Skip to content

Commit

Permalink
Fix log4j package warning on JMeter startup: WARN StatusConsoleListen…
Browse files Browse the repository at this point in the history
…er The use of package scanning to locate plugins is deprecated ...

The Log4j Core `packages` configuration attribute is deprecated because:

* It triggers the scanning of the mentioned packages and slows down the
  startup process.
* It was replaced in version 2.0 by a faster mechanism that relies on a
  `Log4jPlugins.dat` metadata file. See [Log4j Plugins](https://logging.apache.org/log4j/2.x/manual/plugins.html) for more details.

This PR removes the `packages` attribute from the standard configuration
file and configures the build script of `jmeter-core` to use the
`PluginProcessor` contained in `log4j-core`.

See apache#5937.
  • Loading branch information
ppkarwasz authored and vlsi committed Aug 6, 2024
1 parent 174ba31 commit b968bab
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bin/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
~ limitations under the License.
-->

<Configuration status="WARN" packages="org.apache.jmeter.gui.logging">
<Configuration status="WARN">

<Appenders>
<!-- Uncomment to set rotating logs up to 5 files of 100 MB-->
Expand Down
16 changes: 16 additions & 0 deletions src/core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.github.autostyle.gradle.AutostyleTask
import com.github.vlsi.gradle.ide.IdeExtension
import java.util.jar.JarFile

plugins {
id("java-test-fixtures")
Expand Down Expand Up @@ -45,6 +46,9 @@ dependencies {
api("org.apache.logging.log4j:log4j-core") {
because("GuiLogEventAppender is using log4j-core to implement GUI-based log appender")
}
kapt("org.apache.logging.log4j:log4j-core") {
because("Generates a plugin cache file for GuiLogEventAppender")
}
api("org.apache.logging.log4j:log4j-slf4j-impl") {
because("Both log4j and slf4j are included, so it makes sense to just add log4j->slf4j bridge as well")
}
Expand Down Expand Up @@ -188,3 +192,15 @@ tasks.jar {
from("$rootDir/xdocs/images/logo.svg")
}
}

// Checks the generated JAR for a Log4j plugin cache file.
tasks.jar {
doLast {
JarFile(archiveFile.get().asFile).use { jar ->
val entryName = "META-INF/org/apache/logging/log4j/core/config/plugins/Log4j2Plugins.dat"
if (jar.getJarEntry(entryName) == null) {
throw IllegalStateException("$entryName was not found in ${archiveFile.get().asFile}. The entry should be generated by log4j-core annotation processor")
}
}
}
}

0 comments on commit b968bab

Please sign in to comment.