Migration: Apache Log4j version 1 is no longer provided in EAP 8

Updated

Starting with JBoss EAP 8.0 , it no longer provides Apache Log4j version 1 APIs. Any applications that are not packaging log4j.jar and log4j configuration inside of the application would need to be updated.

Impact

If the application is NOT packaging log4j.jar in the application AND any of the following are true, then migration/changes would be required:

  • If you use log4j in your deployment and do not include a log4j configuration file, then you must either migrate to a new logging facade or add a log4j configuration to your deployment. Log messages will no longer be routed based on the logging subsystem.
  • If you use a log4j.xml, log4j.properties or jboss-log4j.xml file in your deployment you must include a log4j.jar in your deployment. Note if it's a jboss-log4j.xml you'll need to rename the file to log4j.xml.
  • JBoss EAP Logging’s custom-handlers will no longer allow log4j v1 appenders to be used
  • If the application classes import classes such as org.apache.log4j.Logger
    • If the application includes a jboss-deployment-structure.xml or has Dependencies: specified in the MANIFEST.MF declaring a module dependency on org.jboss.log4j.logmanager , these dependencies will need to be removed.

Migration

  • Option 1 (Recommended)

    • Update the application classes to use Apache Log4jv2 classes (or one of the other provided Logging APIs provided by JBoss EAP 8)
    • Change classes such as org.apache.log4j.Logger (log4j v1) -> org.apache.logging.log4j.Logger (log4j v2)
    • If the application packages log4j.properties, log4j.xml or jboss-log4j.xml either:
      • Configure the logging in the EAP configuration (Recommended) or
      • Configure it using a logging.properties in the application (the log4jv2 configurations files are not supported in the application, so the logging.properties must be used)
  • Option 2

    • Package the Apache Log4j version 1 jar(s) inside of the application instead of depending on JBoss EAP 8 for the Logging APIs and exclude the JBoss Logging APIs from the application via a jboss-deployment-structure.xml exclude-subsystems on the logging subsystem or by configuring the logging subsystem add-logging-api-dependencies to false so that the logging apis are not provided to any deployment by default, see details below.

Additional Details:

Disable implicit logging dependencies for a particular deployment

In the application's jboss-deployment-structure.xml, use the exclude-subsystems to exclude the logging subsystem such as:

<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
  <deployment>
    <exclude-subsystems>
      <subsystem name="logging"/>
    </exclude-subsystems>
  </deployment>
</jboss-deployment-structure>

If the application is an ear and has a sub deployment named example.war, the jboss-deployment-structure.xml goes in the ear / META-INF/jboss-deployment-structure.xml and the logging subsystem would be excluded by declaring it in the sub-deployment such as :

<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
  <sub-deployment name="example.war">
    <exclude-subsystems>
      <subsystem name="logging"/>
    </exclude-subsystems>
  </sub-deployment>
</jboss-deployment-structure>

Disable implicit logging dependencies for all deployments

Running this CLI command:

/subsystem=logging:write-attribute(name="add-logging-api-dependencies", value="false")

Will change the default to false, so that by default the logging APIs in EAP are not made available to all deployments. A deployment would need to make an explicit dependency on the JBoss Module with the given Logging API via the jboss-deployment-structure.xml or MANIFEST.MF see [1].

<subsystem xmlns="urn:jboss:domain:logging:8.0">
    <add-logging-api-dependencies value="false"/>
  ...
</subsystem>

Notes

  • If the application packages Apache Log4j v1 jars and log4j configuration in the application
    • The application logging is no longer managed by EAP, it is application managed
    • The application should not try to log to the server.log as logging frameworks expect to be the only one writing to a particular log file and unexpected results could occur

[1] How to specify a dependency on a JBoss Module in JBoss EAP 6 / 7

Category
Components
Article Type