Log4j 1.x Bridge Download

16 views
Skip to first unread message

Karlyn Melich

unread,
Jan 17, 2024, 8:03:49 AM1/17/24
to sorsovanee

To use this option, applications need to use the following three jar files:the Log4j 2 API jar (log4j-api.jar),the Log4j 2 implementation jar (log4j-core.jar) andthe Log4j 1.x bridge jar (log4j-1.2-api.jar).

log4j 1.x bridge download

Log4j 2 provides support for the Log4j 1 logging methods by providing alternate implementationsof the classes containing those methods. These classes may be found in the log4j-1.2-api jardistributed with the project. All calls to perform logging will result in the data passed to the logging methodsto be forwarded to the Log4j2 API where they can be processed by implementations of the Log4j 2 API.

Once you have migrated all of your own application and library code under your control, you may not need the bridge anymore.Note that when you use a library/framework that can be configured to use several logging frameworks,then you typically don't need the log4j-1.2-api bridge either,as you may be able to directly configure it to use Log4j v2 instead v1.Some libraries/frameworks even auto-detect the presence of certain logging framework implementations on their classpath,and automagically switch their internal logging delegation accordingly;try simple removing the Log4j v1 dependency instead of replacing it with this bridge,and test if logging from all of your dependencies still work.

While the Log4j 1.x bridge supports logging configurations that use the Log4j 1.x properties or XML format,migrating to the new 2.x format is not difficult.The Log4j 2 website contains extensive documentation on the 2.x configuration format.Examples for migrating logging configurations from the v1 format to the v2 format are below.

If log4j-core is not present location information will not be accurate in calls using the Log4j 1.2 API. The configpackage which attempts to convert Log4j 1.x configurations to Log4j 2 is not supported without Log4j 2.

To use the Log4j Legacy Bridge, you must first identify and remove all the Log4j 1.x JARs from the application andreplace them with the bridge JAR. Once in place, all logging that uses Log4j 1.x will be routed to Log4j 2.

While we have improved the compatibility of the bridge in the past, applications that try to modify legacy Log4jby adding Appenders, Filters, etc, may experience problems. In this case, migrating those components to Log4j 2first is recommended.

I also deleted all logj1 jar like they say on the offical migration guide, i don't know if i have to replace all log4j.xml configuration files with log4j2.xml and change the configuration to the new syntax?If it's the case, how i can do with third parties that use log4j and configure it with log4j.xml ?

Yes, your dependencies are correct. As for whether to use a log4j 1 format configuration or log4j 2 I would always recommend using the log4j 2 format if you can do the work. You can certainly try to use the log4j 1 configurations by following

Often, some of the components you depend on rely on a logging API other than SLF4J. You may also assume that these components will not switch to SLF4J in the immediate future. To deal with such circumstances, SLF4J ships with several bridging modules which redirect calls made to log4j 1.x, JCL and java.util.logging APIs to behave as if they were made to the SLF4J API instead. The figure below illustrates the idea.

SLF4J ships with a module called log4j-over-slf4j. It allows log4j 1.x users (but not log4j 2.x) to migrate existing applications/libraries to SLF4J without changing a single line of code but simply by replacing the log4j.jar file with log4j-over-slf4j.jar, as described below.

The log4j-over-slf4j module contains replacements of most widely used log4j 1.x classes, namely org.apache.log4j.Category, org.apache.log4j.Logger, org.apache.log4j.Priority, org.apache.log4j.Level, org.apache.log4j.MDC, and org.apache.log4j.BasicConfigurator. These replacement classes redirect all work to their corresponding SLF4J classes.

To use log4j-over-slf4j in your own application, the first step is to locate and then to replace log4j.jar with log4j-over-slf4j.jar. Note that you still need an SLF4J binding and its dependencies for log4j-over-slf4j to work properly.

Note that as a result of this migration, log4j 1.x configuration files will no longer be picked up. If you need to migrate your log4j.properties file to logback, the log4j translator might be of help. For configuring logback, please refer to its manual.

The log4j-over-slf4j module will not work when the application calls log4j components that are not present in the bridge. For example, when application code directly references log4j appenders, filters or the PropertyConfigurator, then log4j-over-slf4j would be an insufficient replacement for log4j. However, when log4j is configured through a configuration file, be it log4j.properties or log4j.xml, the log4j-over-slf4j module should just work fine.

The overhead of using log4j-over-slf4j instead of log4j directly is relatively small. Given that log4j-over-slf4j immediately delegates all work to SLF4J, the CPU overhead should be negligible, in the order of a few nanoseconds. There is a memory overhead corresponding to an entry in a hashmap per logger, which should be usually acceptable even for very large applications consisting of several thousand loggers. Moreover, if you choose logback as your underlying logging system, and given that logback is both much faster and more memory-efficient than log4j, the gains made by using logback should compensate for the overhead of using log4j-over-slf4j instead of log4j 1.x directly.

The presence of slf4j-log4j12.jar, that is the log4j binding for SLF4J, will force all SLF4J calls to be delegated to log4j. The presence of log4j-over-slf4j.jar will in turn delegate all log4j API calls to their SLF4J equivalents. If both are present simultaneously, slf4j calls will be delegated to log4j, and log4j calls redirected to SLF4j, resulting in an endless loop.

The presence of slf4j-reload4j.jar, that is the reload4j binding for SLF4J, will force all SLF4J calls to be delegated to reload4j which has the same exact API as log4j 1.x. The presence of log4j-over-slf4j.jar will in turn delegate all reload4j API calls to their SLF4J equivalents. If both are present simultaneously, SLF4J calls will be delegated to reload4j (i.e. a security patched the log4j 1.x), and log4j 1.x calls redirected to SLF4j, resulting in an endless loop.

Note on performance Contrary to other bridging modules, namely jcl-over-slf4j and log4j-over-slf4j, which reimplement JCL and respectively log4j, the jul-to-slf4j module does not reimplement the java.util.logging because packages under the java.* namespace cannot be replaced. Instead, jul-to-slf4j translates LogRecord objects into their SLF4J equivalent. Please note this translation process incurs the cost of constructing a LogRecord instance regardless of whether the SLF4J logger is disabled for the given level or nor. Consequently, j.u.l. to SLF4J translation can seriously increase the cost of disabled logging statements (60-fold or 6000%) and measurably impact the performance of enabled log statements (20% overall increase). As of logback version 0.9.25, it is possible to completely eliminate the 60-fold translation overhead for disabled log statements with the help of LevelChangePropagator.

Those who snoop around may find an artifact called log4j-over-slf4j, but this just a bridge that let us move from log4j to slf4j/logback without modifying every single file that had used a log4j logger.

Note: this document defines a log backend API. The API is not intendedto be called by application developers directly. It is provided for logginglibrary authors to buildlog appenders,which use this API to bridge between existing logging libraries and theOpenTelemetry log data model.

To use the Log4j Legacy Bridge just remove all the Log4j 1.x jars from the application and replace them with the bridge jar. Once in place all logging that uses Log4j 1.x will be routed to Log4j 2. However, applications that attempt to modify legacy Log4j by adding Appenders, Filters, etc may experience problems if they try to verify the success of these actions as these methods are largely no-ops.

I work for a software house and we've used log4j 1.2 in a lot of our older code. Following the recent Logshell incident (which I know doesn't concern log4j 1.2 directly), we've considered migrating to the latest secure release of log4j i.e. 2.17.0 and later. However, we would like to be able to do that without having to change our existing code base.

I came across the log4j-1.2 API bridge which allows us to use log4j2 in the background through the same API as log4j 1.2. However, our custom code uses PropertyConfigurator to configure the logger through log4j 1.2 format properties files, and the API Bridge does not offer an implementation for it. Therefore, our company wants to develop an implementation for the PropertyConfigurator class ourselves. I realize that there is experimental support offered for log4j 1.2 configuration files in log4j 2.13.0 onwards, but we would prefer to have our own implementation.

My understanding is that since log4j (including the API bridge) is under the Apache 2.0 license, it is legal to modify the code and even sell it as a proprietary product as long as I retain the original copyright, license, notice files in the code/artifact and also include a statement of significant changes. However, I also understand that we are not allowed to use trademarks such as the "log4j" name in the product.

I wanted to confirm if it is okay to develop and sell this product under a new name (product name, group name, artifact name), while still retaining the API and package name (org.apache.log4j) from log4j 1.x API. Retaining the package name is essential in order to avoid changing our code base which depends on log4j 1.2. Furthermore, how can I know exactly what is part of the trademarks for log4j? Also are there other conditions that we would be required to meet. Thanks

I dusted off and fixed up two small yet related projects I've had lying around forever.

The first is a substitute java.util.logging LogManager that fixes about 10 zillion bugs, and is all-around much better-behaved (not to mention far simpler) than the default JDK implementation.

The second is a deployable java.util.logging Handler JAR that forwards j.u.l LogRecords to log4j.

The upshot of this thing is, two tiny JARs and you're able to see all j.u.l messages mapped in properly with the regular server log, without having to rearchitecht the whole logging system. While I was hoping to uncover the secrets of the universe, unfortunately on a stock 5.0.0.CR2 startup, the only extra stuff printed was a couple RMI messages. Oh well.

The logmanager source is here (the resultant classes must be on the boot classpath, and the -Djava.util.logging.manager system property must point at the org.jboss.logmanager.LogManager class): -logmanager/trunk

The logbridge deployable is here (make a JAR and stick it in deployers/ to get early logs, or deploy/ if you don't care about that stuff): -logbridge/trunk/

dca57bae1f
Reply all
Reply to author
Forward
0 new messages